0

我是电话编程的新手。图像和音频存储在私人文件夹中,在数据库中我创建了 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/Application Support /iPhone 模拟器/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song.mp3

2|Picture0002|/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 模拟器/5.0/Applications/7CA908BE-79DC-44EE-BEA9-A4DBF1736062/Documents/Tauky/Audios/song1.mp3

现在我在控制台中使用了这样的路径,如果单击该图像意味着它必须在下一个视图中播放歌曲,我只想在表格视图中显示图像。直到现在我能够在表格视图中显示路径而不是路径,如果单击我想播放歌曲的图像,我想显示图像。这想怎么做。是否可以使用路径图像路径和音频路径播放歌曲。

4

1 回答 1

1

声明两个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"];

实现 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委托*

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

}
于 2012-11-22T08:39:04.027 回答