我需要将应用程序文件夹中存储的视频加载到 UITableView 中?
我需要将应用程序文件夹中存储的视频加载到表视图中。当我触摸单元格时,视频就会播放。
我使用以下代码将所有视频文件放入数组中。
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray* contents = [fileManager directoryContentsAtPath:@"/Users/srikanth/Desktop/Projects/UF/Table2/Videos"];
for(a = 1; a < [contents count]; a++)
NSLog(@"Array contents: %@", [contents objectAtIndex:a]);
cells = [[NSMutableArray alloc]initWithCapacity:[contents count]];
但是我怎样才能将视频加载到 UITableView 中呢?我使用 NSBundle 通过给出路径来加载视频。它起作用了。但是,现在我需要从数组内容加载视频。当我触摸表格的单元格时,将加载数组内容 si 中的相应文件。我怎样才能做到呢? 谢谢。
I need to load a video stored in Applications folder in to a table view. When I touched the cell the video plays.
I used the following code to get all the video files in to an array.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray* contents = [fileManager directoryContentsAtPath:@"/Users/srikanth/Desktop/Projects/UF/Table2/Videos"];
for(a = 1; a < [contents count]; a++)
NSLog(@"Array contents: %@", [contents objectAtIndex:a]);
cells = [[NSMutableArray alloc]initWithCapacity:[contents count]];
But how can I load the videos into UITableView. I used NSBundle for loading videos by giving path. It worked. But, now I need the videos to load from the array contents. When I touch the cell of the table the corresponding file from the array contents si to be loaded. How can I make it?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住,iPhone 应用程序是“沙盒”的。与普通应用程序不同,它们只能看到自己目录中的文件。在模拟器或设备中,您不能使用指向模拟器/设备中应用程序目录之外的文件的目录路径。
您尝试从 Mac 桌面读取文件,iPhoneOS 将无法解析该路径。您之前已经能够读取应用程序包中的文件,因为这些文件位于应用程序的目录中。
因此,您需要做的第一件事是将文件移动到模拟器或设备中的应用程序目录中。对于模拟器,应用程序目录的路径将类似于:
~/Library/Application Support/iPhone Simulator/3.2/Applications/#app's UUID#/
将视频放在文档文件夹中。
Remember, iPhone apps are "sandboxed". Unlike normal apps, they can only see the files in their own directory. In either the simulator or the device, you can't use a directory path that leads to files that are outside the application's directory in the simulator/device.
You're trying to read files from your Mac's desktop and the iPhoneOS will not resolve that path. You've been able to read files in the app's bundle before because those files are in the app's directory.
So, the first thing you need to do is to move the files into the app's directory either in the simulator or the device. With the simulator, the path to the app's directory will be something like:
~/Library/Application Support/iPhone Simulator/3.2/Applications/#app's UUID#/
Put the videos in the documentation folder there.