0
votes

I want to pass data from TableView cell but in detailview "SongdetailView" it' s appears only the first value from table.

Here is my code

- (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];
    }
}
1
I'm just wondering, are you sure that sender is a UITableViewCell? I would throw an NSLog(@"%@", sender); statement in there, just to make sure.Mario

1 Answers

0
votes

You can use tag to identify which cell is selected, then get right songid from modal objects.

ex:

in tableView:cellForRowAtIndexPath:

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

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

}

in prepareForSegue:sender:

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