[英]How to get exact PresentingViewController when Modal View dismissed
[英]How can a PresentingViewController get notified that its PresentedViewController dismissed itself?
鑒於:
presentingViewController
屬性除外) dismiss
本身並沒有別的 我要實現的目標:
限制:
到目前為止,我發現了什么:
dismiss(animated:completion:)
將調用轉發到其presentingViewController
。 但是看起來好像不調用dismiss(animated:completion:)
,而是私有方法_performCoordinatedPresentOrDismiss:animated:
presentingViewController
iOS 文檔具有誤導性。 它說“呈現的視圖控制器已將此屬性設置為呈現它的視圖控制器”,但事實並非如此。 在iOS系統中11,這將始終指向根父VC的VC是present
被稱為上。 同樣, presentedViewController
上的文檔具有誤導性。 它說“調用該方法的視圖控制器已將此屬性設置為它所提供的視圖控制器”,但這還不是全部。 調用present
的VC層次結構中的每個VC(所有其父VC和子VC)都將指向同一個presentedViewController
。 在您的Controller A中,將其navigationController:didShowViewController
為UINavigationControllerDelegate
並使用navigationController:didShowViewController
標記控制器B的表示形式( isControllerBisPresented = true
)。 當B的viewDidAppear
時,檢查isControllerBisPresented
是否為true。
一個丑陋的解決方法是使用在deinit
中執行某些操作的deinit
。 所以, A
呈現M
中嵌入B
作為childVC。 當B
自行解散時, M
也將隱式解散,因此應調用它的deinit
方法。 在那里,它可以通知A
被解雇。
這是脆弱的,因為某個參考周期可能阻止M
的重新分配,這將導致A
無法得到通知。 所以我寧願找到一個更好的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.