2013-08-07 106 views
0

我已經採取了一個數組的索引在tableview中顯示,我想玩didSelectRowAtIndexpath這是索引相同。我怎樣才能比較索引iPhone

MPMediaItem *item = [arrAnand objectAtIndex:3]; 
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL]; 
AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url]; 
player2 = [[AVPlayer alloc] initWithPlayerItem:playerItem]; 
[player2 play]; 

在這裏,我有3趟..但我需要的是比賽選擇在沒有選擇行

幫助索引!

回答

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]; 
} 

indexPath.row會給你的直接指標,如果你在你的tableView沒有任何部分。