簡體   English   中英

模態視圖關閉時如何獲取精確的PresentingViewController

[英]How to get exact PresentingViewController when Modal View dismissed

我的應用程序導航如下:

NavigationController ---> RootViewController-(Show Segue)-> SomeViewController-(Show Segue)-> ParentViewController(with ContainerView)

因此,ParentViewController具有容器視圖。 根據用戶選擇,在運行時以編程方式填充此容器視圖。 因此,基本上視圖層次結構是這樣的:

ParentViewController(With ContainerView)---(Embed Segue)-> ContainerViewController-(自定義Segue,用於確定在運行時顯示哪個孩子)-> FirstChildViewController / SecondChildViewController

現在,當在SecondChildViewController中點擊按鈕時,我將顯示一個模式視圖。 到目前為止,一切都很好。

但是,現在我想在解散ModalViewController時更新SecondChildViewController中的數據。 我嘗試在ModalViewController中這樣做:

SecondChildViewController *secondChildVC = (SecondChildViewController *)self.presentingViewController;
[self dismissViewControllerAnimated:YES completion: ^{ [secondChildVC updateList];   }];

但是,我得到以下錯誤:

由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'-[UINavigationController updateList]:無法識別的選擇器已發送到實例0x127e451b0'

如何解決此問題? 因此,具體來說,如何獲得“真實的” presentingViewController? 我知道它有點怪異的導航,並且從用戶體驗的角度來看,視圖上的堆棧太多,但這是客戶端想要實現的方式。

我不確定我是否正確理解了您的問題。 如果您有一個ViewController A,顯示了ViewController B,並且如果您希望在B被解散時在A中調用一個方法,則可以使A成為B的委托。

在此處閱讀有關協議和委托的更多信息: https : //developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM