whose view is not in the window hierarchy!
今天遇到一個問題簡單描述一下:
需求:登入成功之後,需要判斷是否繫結手機,沒有繫結present一個手機頁面,然後Tabbar切換到首頁。這個需求還可以,但是業務裡登入,註冊,忘記密碼等等都是modal出來的。所以登陸完之後不得不全部dissmiss掉,然後再通知到我的介面做相應操作。
遇到問題:
whose view is not in the window hierarchy!
分析:也就是你現在的Present的檢視並不是Windows檢視,因為現在還有沒有dismiss掉的檢視。
解決:1.如果是用錯頂層檢視的可以找到頂層檢視。 2,如果沒有dismiss掉就進行presnt的可以,dissmiss callback進行處理。
程式碼(Swift):
找到頂層檢視:
///獲取當前控制器
func currentVc() ->UIViewController{
var vc = UIApplication.shared.keyWindow?.rootViewController
if (vc?.isKind(of: UITabBarController.self))! {
vc = (vc as! UITabBarController).selectedViewController
}else if (vc?.isKind(of: UINavigationController.self))!{
vc = (vc as! UINavigationController).visibleViewController
}else if ((vc?.presentedViewController) != nil){
vc = vc?.presentedViewController
}
return vc!
}
dismiss所有的介面:
///所有頁面都diss到根目錄
func dissAllToRoot(currentVc:UIViewController,completion: (() -> Swift.Void)? = nil){
var vc = currentVc.presentingViewController
if vc?.presentingViewController == nil {
currentVc.dismiss(animated: true, completion: completion)
}
while ((vc?.presentingViewController) != nil) {
vc = vc?.presentingViewController
}
vc?.dismiss(animated: true, completion: completion)
}
最後就簡單了
dissAllToRoot(currentVc: self) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "****"), object: nil)
}
相關文章
- Window、WindowManager、View 之間的關係View
- Activity、View、Window之間關係的分析View
- Activity啟動分析(二)--建立Window和ViewView
- Android自定義View之Window、ViewRootImpl和View的三大流程AndroidView
- 底層剖析 Window 、Activity、 View 三者關係View
- Android 中MVC例項之Activity,Window和ViewAndroidMVCView
- Provide an Alternative View to Data Using Splitter Window (轉)IDEView
- 怎樣使用Xcode的Debug View Hierarchy工具來除錯Xamarin開發的iOS AppXCodeView除錯iOSAPP
- Android 中Activity,Window和View之間的關係AndroidView
- Fresco原始碼分析之Hierarchy原始碼
- Activity、View、Window的理解一篇文章就夠了View
- Android Tools 之一 Hierarchy ViewerAndroidView
- 聊聊spring security的role hierarchySpring
- spring aop The hierarchy of the type is inconsistentSpring
- 子執行緒呼叫invalidate()產生“Only the original thread that created a view hierarchy can touch its views.”原因分析執行緒threadView
- 圖解Android - Android GUI 系統 (2) - 視窗管理 (View, Canvas, Window Manager)圖解AndroidGUIViewCanvas
- 效能優化工具知識梳理(4) Hierarchy Viewer優化View
- Inheritance with EF Code First: Part 1 – Table per Hierarchy (TPH)
- Hierarchy檢視裡的Transform和Camera元件ORM元件
- oracle中Window和Window GroupOracle
- SAP CRM Product hierarchy,Category和Application三個問題GoAPP
- TypeError: Cannot read private member xxx from an object whose class did not declare itErrorObject
- Android Starting Window(Preview Window)AndroidView
- Android-Window(一)——初識WindowAndroid
- MDN之Window(三)【window.postMessage】
- prevent a Javascript Modal Window to open itself in a new windowJavaScript
- Window mode
- JavaScript WindowJavaScript
- SAP RETAIL 根據Merchandise Category Hierarchy Level查詢物料清單AIGo
- ViewView
- JavaScript window物件JavaScript物件
- window.top
- JavaScript window 物件JavaScript物件
- Squid for windowUI
- window的特性
- KendoUI系列:WindowUI
- WINDOW操作命令
- Android自定義View:View(二)AndroidView