最新消息:20210917 已从crifan.com换到crifan.org

[已解决]swift中showViewController出错:Pushing the same view controller instance more than once is not supported

Swift crifan 2837浏览 0评论

app界面卡死在:

出错:

2016-03-17 17:30:12.057 JianDao[834:119956] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Pushing the same view controller instance more than once is not supported (<JianDao.MessageTableViewController: 0x156e44730>)’
*** First throw call stack:
(0x183031900 0x18269ff80 0x187dba8cc 0x187db9f90 0x187e27044 0x187e54484 0x187e53294 0x187fbe870 0x187d5f394 0x187d5ee90 0x187d5ed18 0x185735c00 0x1017a5bb0 0x1017ab658 0x182fe8bb0 0x182fe6a18 0x182f15680 0x184424088 0x187d8cd90 0x100083444 0x182ab68b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

如图:

暂时不去改了。。。

以后再说。

之后对于代码:

    func sendMessageToPerson(){
        print("sendMessageToPerson")
        let selectedContactMsgTVC:MessageTableViewController = getMsgTVCFromItem(self.curPersonItem)
        self.showViewController(selectedContactMsgTVC, sender: self)
    }

又出现类似的错误:

2016-03-19 15:44:27.247 JianDao[32124:1512303] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Pushing the same view controller instance more than once is not supported (<JianDao.MessageTableViewController: 0x7ce466c0>)’
*** First throw call stack:
(
    0   CoreFoundation                      0x02683a14 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x03d4ae02 objc_exception_throw + 50
    2   UIKit                               0x00ad08df __71-[UINavigationController pushViewController:transition:forceImmediate:]_block_invoke + 0
    3   UIKit                               0x0f40583c -[UINavigationControllerAccessibility pushViewController:transition:forceImmediate:] + 73
    4   UIKit                               0x00acfce5 __54-[UINavigationController pushViewController:animated:]_block_invoke + 491
    5   UIKit                               0x00acfab5 -[UINavigationController pushViewController:animated:] + 786
    6   UIKit                               0x00acf2d8 -[UINavigationController showViewController:sender:] + 170
    7   libobjc.A.dylib                     0x03d5f0b5 -[NSObject performSelector:withObject:withObject:] + 84
    8   UIKit                               0x00a9d857 -[UIViewController _showViewController:withAction:sender:] + 137
    9   UIKit                               0x00a9d976 -[UIViewController showViewController:sender:] + 67
    10  JianDao                             0x002496b1 _TFC7JianDao24PersonInfoViewController19sendMessageToPersonfS0_FT_T_ + 305
    11  JianDao                             0x00249712 _TToFC7JianDao24PersonInfoViewController19sendMessageToPersonfS0_FT_T_ + 34
    12  libobjc.A.dylib                     0x03d5f0b5 -[NSObject performSelector:withObject:withObject:] + 84
    13  UIKit                               0x008b5b79 -[UIApplication sendAction:to:from:forEvent:] + 118
    14  UIKit                               0x008b5af8 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
    15  UIKit                               0x00a558f8 -[UIControl sendAction:to:forEvent:] + 79
    16  UIKit                               0x00a55c78 -[UIControl _sendActionsForEvents:withEvent:] + 408
    17  UIKit                               0x00a54c7e -[UIControl touchesEnded:withEvent:] + 714
    18  UIKit                               0x00932182 -[UIWindow _sendTouchesForEvent:] + 1095
    19  UIKit                               0x00933220 -[UIWindow sendEvent:] + 1159
    20  UIKit                               0x008d7f93 -[UIApplication sendEvent:] + 266
    21  UIKit                               0x0f3bf657 -[UIApplicationAccessibility sendEvent:] + 72
    22  UIKit                               0x008ad668 _UIApplicationHandleEventQueue + 7802
    23  CoreFoundation                      0x0259d6ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    24  CoreFoundation                      0x0259338b __CFRunLoopDoSources0 + 523
    25  CoreFoundation                      0x025927a8 __CFRunLoopRun + 1032
    26  CoreFoundation                      0x025920e6 CFRunLoopRunSpecific + 470
    27  CoreFoundation                      0x02591efb CFRunLoopRunInMode + 123
    28  GraphicsServices                    0x05b36664 GSEventRunModal + 192
    29  GraphicsServices                    0x05b364a1 GSEventRun + 104
    30  UIKit                               0x008b3bfa UIApplicationMain + 160
    31  JianDao                             0x00085ccc main + 140
    32  libdyld.dylib                       0x04a88a21 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

如图:

很明显:

此处是已经有了此视图(聊天对话的视图),但是又再次加入视图堆栈,所以报错,不支持。

搜:

参考:

ios – Pushing View Controller more than once is not supported? – Stack Overflow

iphone – "Pushing the same view controller instance more than once is not supported" exception – Stack Overflow

ios – NSInvalidArgumentException :Pushing the same view controller instance more than once is not supported – Stack Overflow

【原】push过快的错误 (Pushing the same view controller instance more than once is not supported) – MichaelMao – 博客园

Pushing the same view controller instance more … | Apple Support Communities

【总结】

最后改为:

        let selectedContactMsgTVC:MessageTableViewController = getMsgTVCFromItem(self.curPersonItem)
        doShowViewController(self, vcToShow: selectedContactMsgTVC)
func doShowViewController(curVc:UIViewController, vcToShow:UIViewController) {
    print("doShowViewController curVc=\(curVc), vcToShow=\(vcToShow)")
    //doShowViewController curVc=<JianDao.PersonInfoViewController: 0x7aeebe10>, vcToShow=<JianDao.MessageTableViewController: 0x79f80b80>
    if existedViewController(vcToShow) {
        //pop to that view controller
        //            print("curVc.navigationController?.viewControllers=\(curVc.navigationController?.viewControllers)")
        curVc.navigationController?.popToViewController(vcToShow, animated: true)
        //            print("curVc.navigationController?.viewControllers=\(curVc.navigationController?.viewControllers)")
    } else {
        curVc.showViewController(vcToShow, sender: curVc)
    }
}

即可避免重复的视图被push到navi controller中了。

转载请注明:在路上 » [已解决]swift中showViewController出错:Pushing the same view controller instance more than once is not supported

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
101 queries in 0.202 seconds, using 23.33MB memory