我如何比较iPhone中的索引



我已经获取了表视图中显示的数组的索引,并且我想在索引中相同的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号通行证。。但我需要匹配的索引来选择行

救命!!

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将为您提供直接索引。

最新更新