用了:
self.dismissViewControllerAnimated(true, completion: nil) |
结果出错:
2015-12-06 16:13:39.163 JianDao[6147:179128] *** Assertion failure in -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UIApplication.m:1698 2015-12-06 16:13:39.178 JianDao[6147:179128] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘accessing _cachedSystemAnimationFence requires the main thread’ *** First throw call stack: ( 0 CoreFoundation 0x00000001060a7f45 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000105340deb objc_exception_throw + 48 2 CoreFoundation 0x00000001060a7daa +[NSException raise:format:arguments:] + 106 3 Foundation 0x0000000104f8d5ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 4 UIKit 0x0000000106badbfd -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] + 210 5 UIKit 0x0000000106c315e2 +[UIWindow _synchronizeDrawingWithPreCommitHandler:] + 60 6 UIKit 0x000000010720f2f2 -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:] + 99 7 UIKit 0x00000001074fdcca -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1589 8 UIKit 0x0000000107505aab __43-[UIInputWindowController setInputViewSet:]_block_invoke1238 + 98 9 UIKit 0x00000001074f9968 -[UIInputWindowController performOperations:withTemplateNotificationInfo:] + 42 10 UIKit 0x0000000107505765 -[UIInputWindowController setInputViewSet:] + 1194 11 UIKit 0x00000001074fd48e -[UIInputWindowController performOperations:withAnimationStyle:] + 50 12 UIKit 0x0000000107207de5 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1275 13 UIKit 0x0000000107209206 -[UIPeripheralHost(UIKitInternal) _restoreInputViewsWithId:animated:] + 326 14 UIKit 0x0000000106d61b28 -[UIViewController _restoreInputViewsForPresentation] + 268 15 UIKit 0x0000000106d1d0c5 -[UIPresentationController runTransitionForCurrentState] + 1498 16 UIKit 0x0000000106d1b48b -[UIPresentationController _dismissWithAnimationController:interactionController:target:didEndSelector:] + 676 17 UIKit 0x0000000106d6161e -[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:] + 569 18 UIKit 0x0000000106d611da -[UIViewController _dismissViewControllerWithTransition:from:completion:] + 995 19 UIKit 0x0000000106d607bc -[UIViewController dismissViewControllerWithTransition:completion:] + 1273 20 UIKit 0x0000000106d60523 -[UIViewController dismissViewControllerWithTransition:completion:] + 608 21 UIKit 0x0000000106d5fc5c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 489 22 UIKit 0x0000000106d63221 -[UIViewController dismissViewControllerAnimated:completion:] + 149 23 JianDao 0x0000000104977372 _TFC7JianDao30RegisterUsernameViewController23registerJsonDictHandlerfS0_FTSb10extraParasGSqPSs9AnyObject__8jsonDictVS_4JSON_T_ + 578 24 JianDao 0x00000001049786f0 _TPA + 32 25 JianDao 0x00000001049bdefe _TTSf2n_n_d_i_n_n_n_n___TFF7JianDao24getUrlRespJsonDict_asyncFTSS10extraParasGSqPSs9AnyObject__19respJsonDictHandlerFTSbGSqPS0___VS_4JSON_T__T_U_FCS_8ResponseT_ + 5102 26 JianDao 0x00000001049bae9c _TPA__TTSf2n_n_d_i_n_n_n_n___TFF7JianDao24getUrlRespJsonDict_asyncFTSS10extraParasGSqPSs9AnyObject__19respJsonDictHandlerFTSbGSqPS0___VS_4JSON_T__T_U_FCS_8ResponseT_ + 316 27 JianDao 0x00000001049f3237 _TTRXFo_oC7JianDao8Response_dT__XFo_iS0__iT__ + 23 28 JianDao 0x00000001049f23e1 _TPA__TTRXFo_oC7JianDao8Response_dT__XFo_iS0__iT__ + 81 29 JianDao 0x00000001049f3090 _TTRXFo_iC7JianDao8Response_iT__XFo_oS0__dT__ + 32 30 JianDao 0x00000001049f30fe _TFFC7JianDao4HTTPW8onFinishGSqFCS_8ResponseT__U_FS1_T_ + 94 31 JianDao 0x00000001049f3237 _TTRXFo_oC7JianDao8Response_dT__XFo_iS0__iT__ + 23 32 JianDao 0x00000001049f27a1 _TPA__TTRXFo_oC7JianDao8Response_dT__XFo_iS0__iT__31 + 81 33 JianDao 0x00000001049f124b _TFC7JianDao15DelegateManager10URLSessionfS0_FTCSo12NSURLSession4taskCSo16NSURLSessionTask20didCompleteWithErrorGSqCSo7NSError__T_ + 1723 34 JianDao 0x00000001049f1340 _TToFC7JianDao15DelegateManager10URLSessionfS0_FTCSo12NSURLSession4taskCSo16NSURLSessionTask20didCompleteWithErrorGSqCSo7NSError__T_ + 96 35 CFNetwork 0x00000001058d61cf __51-[NSURLSession delegate_task:didCompleteWithError:]_block_invoke170 + 76 36 Foundation 0x0000000104fb53b8 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7 37 Foundation 0x0000000104ef10e5 -[NSBlockOperation main] + 101 38 Foundation 0x0000000104ed4036 -[__NSOperationInternal _start:] + 646 39 Foundation 0x0000000104ed3c47 __NSOQSchedule_f + 194 40 libdispatch.dylib 0x0000000108a3f49b _dispatch_client_callout + 8 41 libdispatch.dylib 0x0000000108a258ec _dispatch_queue_drain + 2215 42 libdispatch.dylib 0x0000000108a24e0d _dispatch_queue_invoke + 601 43 libdispatch.dylib 0x0000000108a27a56 _dispatch_root_queue_drain + 1420 44 libdispatch.dylib 0x0000000108a274c5 _dispatch_worker_thread3 + 111 45 libsystem_pthread.dylib 0x0000000108d704f2 _pthread_wqthread + 1129 46 libsystem_pthread.dylib 0x0000000108d6e375 start_wqthread + 13 ) libc++abi.dylib: terminating with uncaught exception of type NSException |
然后去用变量:
print("gRegisterPhoneViewController=\(gRegisterPhoneViewController)") print("gRegisterUsernameViewController=\(gRegisterUsernameViewController)") gRegisterPhoneViewController?.dismissViewControllerAnimated(false, completion: nil) gRegisterUsernameViewController?.dismissViewControllerAnimated(false, completion: nil) |
结果也还是不行:
只能消失掉当前的页面。
上一级的页面没有消失。
swift dismiss parent view
ios – calling parents viewcontroller method when dismissing child viewcontroller – Stack Overflow
ios – how to dismiss view controller in swift? – Stack Overflow
试试:
dispatch_async(dispatch_get_main_queue(), { () -> Void in // gRegisterPhoneViewController.dismissViewControllerAnimated(false, completion: nil) // gRegisterUsernameViewController?.dismissViewControllerAnimated(false, completion: nil) self.dismissViewControllerAnimated(true, completion: { self.parentViewController?.dismissViewControllerAnimated(false, completion: nil) }) }) |
【总结】
后来才发现:
原来之前是搞错了:
gRegisterPhoneViewController
和:
gRegisterUsernameViewController
其实不是当时所使用的VC
当时正在使用的家了navigation的:
gRegisterPhoneNVC和gRegisterUsernameNVC:
var gRegisterPhoneVC:RegisterPhoneViewController = RegisterPhoneViewController() var gRegisterPhoneNVC:UINavigationController = UINavigationController(rootViewController: gRegisterPhoneVC)var gRegisterUsernameVC:RegisterUsernameViewController? var gRegisterUsernameNVC:UINavigationController? |
然后去用:
dispatch_async(dispatch_get_main_queue(), { () -> Void in gRegisterPhoneNVC.dismissViewControllerAnimated(false, completion: { gRegisterPhoneNVC.dismissViewControllerAnimated(false, completion: nil) } ) }) |
即可实现,在注册完毕后,关闭之前的2层的视图。
转载请注明:在路上 » [已解决]swift让当前视图ViewController消失