iphone - 如何在iPhone中使用图像路径和音频路径播放带有图像的歌曲

标签 iphone objective-c ios uiimageview avaudioplayer

我是电话编程的新手。图像和音频我存储在私有(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"];

Implement UITableView

-(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/

相关文章:

iphone 应用程序 : cannot retrieve property from a Custom Singleton

ios - 如何使用后退按钮使导航栏透明,并且 webView 将显示到状态栏的边缘

ios - 在 iOS 上的 Chrome 中禁用第三方 cookie

ios - Xcode 核心数据终止问题?

ios - IOS 7中UINavigationBar下的白线

iphone - 在 CSS3 中均匀分布菜单选项卡

ios - 安装pod文件后改了工程名,没想到遇到如下问题

ios - 为什么我们在react-native中使用ProgressViewIOS组件的progressImage属性?

objective-c - 使用不活动的应用程序(后台)

ios - 如何知道选择了哪个部分? swift