2014-10-28 91 views
0

有关获取文档文件夹中文件URL的问题。在NSURL中存储本地路径

我想把本地URL带到下一个viewcontroller播放歌曲。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
MSHLocalPlayerVC *playerVC = [segue destinationViewController]; 
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
NSString *strURL = [documentsPath stringByAppendingPathComponent: [self.filePathArray objectAtIndex:[self.tableView indexPathForSelectedRow].row]]; 

playerVC.urlLocalSong = [NSURL URLWithString:strURL]; 
... 
} 

结果:

strURL: /var/mobile/Containers/Data/Application/64000095-51F9-47D1-B152-6D1F8369A01F/Documents/mySong.mp3

playerVC.urlLocalSong:nil

为什么?

回答

2

尝试使用playerVC.urlLocalSong = [NSURL fileURLWithPath:strURL];

+0

哦,哇,谢谢! – CalZone 2014-10-28 22:37:19