声明两个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
}