Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prepareForSegue called before didSelectRowAtIndexPath only when third segue is added

I have 3 segues to 3 different views. 2 are implemented with no problem, it is when the third is created that the problems occur.

I have the following didSelectRowAtIndexPath method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{     NSLog(@" ----------  did select row");      if(indexPath.section == 0){         if(indexPath.row == [self.data count]-1){             //prior to adding this, everything works             [self performSegueWithIdentifier:@"MoreComments" sender:self];         }else{             [self performSegueWithIdentifier:@"FriendView" sender:friend];         }     }else if(indexPath.section == 1){         if(indexPath.row == [self.data2 count]-1){             [self performSegueWithIdentifier:@"MorePosts" sender:self];         }else{             [self performSegueWithIdentifier:@"FriendView" sender:friend];         }     } } 

I have the following prepareForSeque method:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{     if([segue.identifier isEqualToString:@"MorePosts"]){         MorePostsViewController *mfamvc = segue.destinationViewController;         mfamvc.data = self.data;     }else if([segue.identifier isEqualToString:@"FriendView"]){         FriendViewController *fvc = segue.destinationViewController;         fvc.friend = friend;     }else if([segue.identifier isEqualToString:@"MoreComments"]){           MoreCommentsViewController *mcvc = segue.destinationViewController;           mcvc.data = self.data2;     } } 

Before control dragging from my cell to the last view I can see that my program hits didselectrow and then prepareforseque. This makes all the view navigation work perfect.

As soon as I control drag from my cell to the MoreCommentsViewController I start to see the error:

nested push animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

I notice that now also prepareforseque is being called twice, with prepareforseque being called first, then didselectrow, then prepareforsegue again.

What am I doing wrong to conditionally go to these different views?

like image 236
Atma Avatar asked Aug 10 '13 19:08

Atma


2 Answers

You should use either didSelectRowAtIndexPath or segues from cell, but not both. If you want your didSelectRowAtIndexPath to invoke segues, those segues should not be from the cell to the next scene, but rather from the view controller icon in the bar above the scene:

segue between view controllers

You can now select this new segue, go to the "attributes inspector" (option+command+4), and supply a storyboard identifier which you can reference in your code when you call performSegueWithIdentifier.

like image 145
Rob Avatar answered Sep 23 '22 17:09

Rob


The reason is you can't drag from a tableview cell to multiple views. As @rdelmar mentioned this is wrong. You should drag from the destination to the source view and then handle manually the way I did above.

Also can be found here: Conditional segue performed on tap on UITableViewCell

like image 35
Atma Avatar answered Sep 23 '22 17:09

Atma