Search code examples
objective-ciosuitableviewdelegatesdatasource

How to segue from a custom delegate and datasource


I have a view with 2 tableviews in it. This view has the controller PlayerDetailController Now to control the 2 tableviews I have 2 other controllers.

  • tablePlayersDataSourceDelegate
  • tablePlayerNewsDataSourceDelegate

I ctrl-dragged from the PlayerDetail view to the newsView to make a segue. In my tablePlayerDataSourceDelegate I've the following methods to preform this segue.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   [self performSegueWithIdentifier:@"showPlayerDetailNews" sender:indexPath];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSIndexPath *indexPath = (NSIndexPath *)sender;
    PlayerNews *news = [_tableSource objectAtIndex:indexPath.row]; // ask NSFRC for the NSMO at the row in question
    if ([segue.identifier isEqualToString:@"show detail"]) {
        [segue.destinationViewController setImageURL:[NSURL URLWithString:news.image]];
        [segue.destinationViewController setNewsTitle:news.title];
        [segue.destinationViewController setNewsDescription:news.content];
        [segue.destinationViewController setNewsCopy:news.image_copyright];
        [segue.destinationViewController setNewsUrl:news.url];
        [segue.destinationViewController setNewsShortDescription:news.summary];
    }
}

But when I test I get the following error.

** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<tblPlayerNewsDatasourceDelagete: 0x1e5e44c0>) has no segue with identifier 'showPlayerDetailNews''

I get why this is giving the error. Because the playerDetail view uses the class playerDetailController and I am trying to do te segue in the tablePlayerNewsDelegate class. Do you maybe know a way to work around it?

EDIT Here you see a picture of what I am talking about

So you can see the two tableviews in the playerDetailView. When a cell in the bottom tableview is clicked it should go to the next view.

EDIT2

This is what I do in my playerDetailController to fill up my tableview. I've put this in my viewDidLoad.

tabelPlayerNews=[[tblPlayerNewsDatasourceDelagete alloc]init];
[tabelPlayerNews setTableSource:_newsArray];
tblNews.dataSource=tabelPlayerNews;
tblNews.delegate=tabelPlayerNews;
tabelPlayerNews.view=tabelPlayerNews.tableView;

Solution

  • I'm not sure whether I understand that or not but in general....

    To use performSegueWithIdentifier: the drag for the segue should start at the controller that will make the call, not at a view or other object. I think that's what the error message is telling you: assuming there's a segue called "showPlayerDetailNews" in your storyboard, it doesn't belong to the correct object.