Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
311 views
in Technique[技术] by (71.8m points)

ios - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...