Reputation: 3120
I have an issue with segue when clicking on cell and trying to transfer my date to DetailViewController
I didn't find here answers to my question, so I am asking here.
Here is my Method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// NSLog(@"Source Controller = %@", [segue sourceViewController]);
// NSLog(@"Destination Controller = %@", [segue destinationViewController]);
// NSLog(@"Segue Identifier = %@", [segue identifier]);
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
if (indexPath){
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
NSLog(@"%@", item.title);
}
}
if I will remove if condition only and leave my code like this one:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// NSLog(@"Source Controller = %@", [segue sourceViewController]);
// NSLog(@"Destination Controller = %@", [segue destinationViewController]);
// NSLog(@"Segue Identifier = %@", [segue identifier]);
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
NSLog(@"%@", item.title);
}
my data can be transferred but only always first cell.
If I will implement it like this one:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"detailNews"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//if (indexPath){
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
NSLog(@"%@", item.category);
}
}
it will send but always a title of news and always from first news. (NSLOG only for checking)
I know it receives all values, I have checked it by NSLOG, not only the title.
For your information I have always latest 20 news parsed from web site That's working and my cells filled by news titles.
Could you please suggest me where I am wrong?
Thank you
Upvotes: 3
Views: 2881
Reputation: 3120
Ok I think I solved my last issue. I have forgotten connect my IBOUTLET Tableview to my viewcontroller. That's it
Upvotes: 2
Reputation: 795
if "sender" is the cell that's calling this, you can do:
NSIndexPath *indexPath = [[self tableView] indexPathForCell:sender];
lastNews *item = [news objectAtIndex:indexPath.row];
[segue.destinationViewController setDetail:item];
Upvotes: 8