日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

iOS开发出错whose view is not in the window hierarchy!的解决

發布時間:2023/12/19 windows 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS开发出错whose view is not in the window hierarchy!的解决 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

大熊貓豬·侯佩原創或翻譯作品.歡迎轉載,轉載請注明出處.
如果覺得寫的不好請多提意見,如果覺得不錯請多多支持點贊.謝謝! hopy ;)


一個簡單的單窗口App在運行時出現錯誤:

2016-04-07 14:28:48.411 BlurViewAndPopView[4364:168520] Warning: Attempt to present <UIAlertController: 0x7a0a4e00> on <BlurViewAndPopView.ViewController: 0x797757d0> whose view is not in the window hierarchy!2016-04-07 14:28:48.935 BlurViewAndPopView[4364:168520] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7a0a4e00>)

該app的功能是在root VC中彈出一個popover視圖,其中包含一個表視圖,在點擊表視圖中的某一行時回調root VC中的閉包,完成改行內容的對話框彈出效果.

分析如下:根據錯誤信息,可以清楚看到在試圖彈出對話框時,root VC不在窗口的繼承體系中,這意味著此時root VC不在window中.

查看popover的cellSelect回調方法:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {let selectedItem = items[indexPath]selectionHandler?(selectedItem: selectedItem)dismissViewControllerAnimated(true, completion: nil)}

可以看到在調用root VC注冊的selectionHandler閉包之后才做的dismissVC的操作,這顯然順序不對!

我們可以這樣修改:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {let selectedItem = items[indexPath]defer {selectionHandler?(selectedItem: selectedItem)}dismissViewControllerAnimated(true, completion: nil)}

好了!現在將selectionHandler的回調放到final中,即可保證在root VC中的操作是在dismissVC之后才開始的,這是root VC應該在window的繼承體系中了.

總結

以上是生活随笔為你收集整理的iOS开发出错whose view is not in the window hierarchy!的解决的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。