Ios NSInvalidArgumentException:不支持多次推送同一视图控制器实例

Ios NSInvalidArgumentException:不支持多次推送同一视图控制器实例,ios,uinavigationcontroller,uistoryboardsegue,Ios,Uinavigationcontroller,Uistoryboardsegue,应用程序因此错误而崩溃 NSInvalidArgumentException :Pushing the same view controller instance more than once is not supported 尝试从另一个导航控制器的UIBarButtonim推送另一个navigationcontroller时出错 控制台中显示的消息: UINavigationController pushViewController:transition:forceImmediate:]

应用程序因此错误而崩溃

NSInvalidArgumentException :Pushing the same view controller instance more than once is not supported 
尝试从另一个导航控制器的UIBarButtonim推送另一个navigationcontroller时出错

控制台中显示的消息:

UINavigationController pushViewController:transition:forceImmediate:]_block_invoke + 0
这是序列编码

else if ([segue.identifier isEqualToString:@"showGroupView"]) {
        GroupView *groupView  = (GroupView *)segue.destinationViewController;

        [self.navigationController pushViewController:groupView animated:YES];
}

如果有人可以帮助解决此错误,则错误消息会准确地告诉您问题所在:您正试图推送已在堆栈上的视图控制器实例

NSInvalidArgumentException :Pushing the same view controller instance more than once is not supported 
换句话说,
segue.destinationViewController
已被推送,因此它要么是当前视图控制器的父级之一,要么是当前控制器本身

如果不查看您的代码,就无法确定其实际原因。您可能遇到与类似的问题,因为运行时允许事件发生两次。同样有可能的是,与segue有关的东西被关闭了


作为第一步,我建议将日志语句添加到segue中(而不是断点,因为它们会改变可观察的行为),以便查看它是否被多次调用(因此类似于链接的问题)。

这是我如何检查我的视图控制器是否在导航堆栈上的 但这实际上解决了我的问题

if ([[self.navigationController topViewController] isKindOfClass:[groupView class]]){
          self.navigationController.navigationBarHidden = YES;
      }else{
          self.navigationController.navigationBarHidden = NO;
      }
所以整个代码是这样的,供任何人参考

else if ([segue.identifier isEqualToString:@"showGroupView"]) {
          GroupView *groupView  = (GroupView *)segue.destinationViewController;
      if ([[self.navigationController topViewController] isKindOfClass:[groupView class]]){
          self.navigationController.navigationBarHidden = YES;
      }else{
          self.navigationController.navigationBarHidden = NO;
      }
      NSLog(@"showGroupViewsegued");

  }

对于Suiteson,应删除“[self.navigationController pushViewController:groupView animated:YES];”,它将跳转到特定segue.DestingViewController的故事板

我自己测试

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// 只作为传值使用 不用再进行导航控制器的 跳转操作
//无需导航来推送或显示

if ([segue.destinationViewController isKindOfClass:[AddCategory class]]) {
    AddCategory *controller = (AddCategory *)segue.destinationViewController;
    controller.categoryText = sender;
 }
 if ([segue.identifier isEqualToString:@"AddCategory"]) {
    //进入到下一步骤 :只作为传值使用
//specilized

}else if ([segue.identifier isEqualToString:@"AddCategory2"]){

 }

}在我的情况下,第一次推的速度不够快,所以我遇到了同样的问题。修正是检查情况:

if (targetViewController == self.navigationController?.topViewController) {
  NSLog("ignore double")
} else {
  self.navigationController!.pushViewController(targetViewController, animated: true)
}

如果您使用的是segue,那么您不应该同时插入代码。做一个或另一个,不要两个都做。谢谢你的帮助,虽然我解决了我的问题。谢谢你的回复。谢谢