Reputation: 13
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]; } }
Upvotes: 0
Views: 702
Reputation: 648
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;
}
}
}
Upvotes: 0