我是电话编程的新手。图像和音频我存储在私有(private)文档文件夹中,在数据库中我创建了 ID、名称、图像路径、音频路径,我已将所有这些想法存储在数据库中。当我从中检索数据时数据库在控制台中的显示如下。
1|Picture0001|/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0001.jpg|/Users/User/Library/应用程序支持/iPhone模拟器/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song.mp3
2|Picture0002|/用户/用户/库/应用程序支持/iPhone模拟器/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0002.jpg|/Users/User/Library/应用程序支持/iPhone模拟器/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song1.mp3
现在我在控制台中使用这个路径得到了这样的路径,我想在表格 View 中仅显示图像,如果单击该图像意味着它必须在下一个 View 中播放歌曲。到目前为止我所做的我能够在表格 View 中显示路径而不是路径,如果单击我想播放歌曲的图像,我想显示图像。这想如何做任何想法。是否可以使用路径图像路径和音频路径播放歌曲。
最佳答案
声明两个NSMutableArray属性(使用一个类而不是两个NSMutableArray)
@property (strong,nonatomic) NSMutableArray *imageCollection;
@property (strong,nonatomic) NSMutableArray *songCollection;
在viewDidLoad
中分配它们
self.imageCollection = [[NSMutableArray alloc] init];
self.songCollection = [[NSMutableArray alloc] init];
添加对象
[self.imageCollection addObject:@"Picture0001"];
[self.imageCollection addObject:@"Picture0002"];
[self.songCollection addObject:@"/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0001.jpg|/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song.mp3"];
[self.songCollection addObject:@"/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Images/Picture0002.jpg|/Users/User/Library/Application Support/iPhone Simulator/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song1.mp3"];
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero] autorelease];
}
cell.textLabel.font = [UIFont systemFontOfSize:12];
NSString *imageName = [self.imageCollection objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:imageName];
cell.textLabel.text = [arry objectAtIndex:indexPath.row];
return cell;
}
实现 UitableView *didSelectRowAtIndexPath委托(delegate)*
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *songURL = [self.songCollection objectAtIndex:indexPath.row];
//play song here or pass the songURL to another controller and play it in view didload
}
关于iphone - 如何在iPhone中使用图像路径和音频路径播放带有图像的歌曲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13507965/