2014-10-28 100 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