Ios prepareForSegue tableview单元格仅详细显示表中的第一个值

Ios prepareForSegue tableview单元格仅详细显示表中的第一个值,ios,objective-c,tableview,cell,Ios,Objective C,Tableview,Cell,我想从TableView单元格传递数据,但在detailview“SongdetailView”中,它只显示表中的第一个值 这是我的密码 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"SongDetails"]) { SongsDetailView *destViewController = segue.de

我想从TableView单元格传递数据,但在detailview“SongdetailView”中,它只显示表中的第一个值

这是我的密码

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"SongDetails"]) { SongsDetailView *destViewController = segue.destinationViewController; NSIndexPath *indexPath = [self.utableView indexPathForCell:sender];; destViewController.recipeName =[ songid objectAtIndex:indexPath.row]; } } -(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方{ if([segue.identifier IsequalString:@“SongDetails”]){ SongsDetailView*destViewController=segue.destinationViewController; nsindepath*indepath=[self.utableView indexPathForCell:sender];; destViewController.recipeName=[songid objectAtIndex:indexPath.row]; } }
您可以使用
标记
来标识选择的单元格,然后从模态对象中获取正确的songid

例:

tableView:cellforrowatinexpath:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath {

    UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    cell.tag = indexPath.row;
    ...

}
prepareForSegue中:发件人:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"SongDetails"]) {

        UITableViewCell *cell = (UITableViewCell*)sender;
        if (cell.tag < self.SongIds.count) {
            SongId *songId = (SongId*)self.SongIds[cell.tag];
            SongsDetailView *destViewController = segue.destinationViewController;
            destViewController.recipeName = songId;
        }
    }
}
-(void)prepareforsgue:(UIStoryboardSegue*)分段发送方:(id)发送方{
if([segue.identifier IsequalString:@“SongDetails”]){
UITableViewCell*单元格=(UITableViewCell*)发送方;
if(cell.tag
我只是想知道,您确定
发送方
是UITableViewCell吗?我会抛出一个
NSLog(@“%@”,发送方)语句,只是为了确保。