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
- Android自定義View之Window、ViewRootImpl和View的三大流程AndroidView
- Activity、View、Window之間關係的分析View
- 底層剖析 Window 、Activity、 View 三者關係View
- 子執行緒呼叫invalidate()產生“Only the original thread that created a view hierarchy can touch its views.”原因分析執行緒threadView
- Fresco原始碼分析之Hierarchy原始碼
- Android Tools 之一 Hierarchy ViewerAndroidView
- 圖解Android - Android GUI 系統 (2) - 視窗管理 (View, Canvas, Window Manager)圖解AndroidGUIViewCanvas
- TypeError: Cannot read private member xxx from an object whose class did not declare itErrorObject
- Warning: Variable 'a' cannot be saved to a MAT-file whose version is older than 7.3.
- SAP CRM Product hierarchy,Category和Application三個問題GoAPP
- SAP RETAIL 根據Merchandise Category Hierarchy Level查詢物料清單AIGo
- Android自定義View:View(二)AndroidView
- MDN之Window(三)【window.postMessage】
- Android-Window(一)——初識WindowAndroid
- ViewView
- Android View 系統 1 - View樹AndroidView
- JavaScript WindowJavaScript
- window.location.replace vs window.location.href
- Android自定義view-自繪ViewAndroidView
- Materialized ViewZedView
- lateral viewView
- window.top
- window.screenY
- moving window baseline
- window的特性
- window.parent
- window.self
- window.screenX
- window.innerHeight
- JavaScript window物件JavaScript物件
- window.opener
- window.outerWidth
- window.outerHeight
- window.location.href與window.location.hash區別
- View 體系詳解:View 的工作流程View
- Android XML佈局報錯:android/view/View$OnUnhandledKeyEventListenerAndroidXMLView
- ABAP webdynpro的view navigation和WebUI的view navigationWebViewNavigationUI