我已经获取了一个数组的索引,这些索引显示在tableview中,我想在didSelectRowAtIndexpath
玩,索引相同。
MPMediaItem *item = [arrAnand objectAtIndex:3];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
player2 = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player2 play];
这里我已经通过了3 ..但我需要匹配的索引才能选择行
帮助!
答案 0 :(得分:1)
tableView:didSelectRowAtIndexpath:
传递一个IndexPath对象,该对象包含所选表格单元格的索引:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMediaItem *item = [arrAnand objectAtIndex:indexPath.row];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
player2 = [[AVPlayer alloc] initWithPlayerItem:playerItem];
[player2 play];
}
如果你的tableView中没有任何部分,indexPath.row
将为你提供直接索引。