“Pushing the same view controller instance more than once is not supported” exception

前端 未结 13 1083
独厮守ぢ
独厮守ぢ 2020-12-02 17:04

I am using the following code to retrieve some messages and putting them into my inbox.

MyInboxVC *inboxVC=[MyInboxVC get ];
//upload all the pending messag         


        
13条回答
  •  隐瞒了意图╮
    2020-12-02 17:23

    Make sure you are not adding the view controller twice in the navigation stack. Eg - in below example self.mainViewC is pushed twice because it is initially instantiated in the navController, and is then pushed onto the navController again in the last line, which would cause this issue.

      navController=[[UINavigationController alloc] initWithRootViewController:self.mainViewC];  
      self.window.rootViewController = navController;
      [self.window makeKeyAndVisible];        
      [navController pushViewController:self.mainViewC animated:NO]; 
    

    In this case mainViewC has already been added to stack when initWithRootViewController was written. There is no need of pushViewController again.

提交回复
热议问题