簡體   English   中英

關閉模態視圖 controller 后重新加載 gridView 數據時出現問題

[英]Problem reloading gridView data after dismissing a modal view controller

我正在展示一個模態視圖 controller 以顯示詳細信息。 我進行了設置,以便對模態視圖 controller 中信息的任何更改都會更改其父視圖 controller 中的信息。

信息已更改,但當模式視圖 controller 被解除時,我無法重新加載 gridView 數據。 現在我可以在模態視圖 controller 中關閉模態。 一切正常,我只是無法從模態視圖 controller 重新加載 gridView 的數據。

我在某處讀到,其中一個選項是創建一個委托,該委托將能夠從父視圖 controller 中關閉模態視圖 controller,我似乎無法通過執行此操作找到有關如何使用 Z34D1F91FB2E514B8A567A 的示例或很好的教程。 事實是,我知道如何使用代表,但不太確定如何正確實施。

誰能在這里指出我正確的方向? 也許有人有更好的選擇。 我願意接受任何建議。

如果我清楚地理解,當您關閉模態視圖 controller 時,您想重新加載父視圖 controller 中包含的網格。 如果是這樣,這里如何:

通過執行類似的操作在您的 ModalViewController 中聲明一個協議

@protocol MyViewControllerDelegate;

@interface MyViewController : UIViewController {

    id<MyViewControllerDelegate>delegate;
    // Your stuff
}

@property (nonatomic, assign) id<MyViewControllerDelegate>delegate;

@end

@protocol MyViewControllerDelegate <NSObject>

-(void)viewControllerWasDismissedOrAnyOtherNameYoudLike;

@end

在您的.m 文件中,只需 @synthesize 委托。

就在你調用dismissModalViewController:animated:時,也調用[delegate viewControllerWasDismissedOrAnyOtherNameYoudLike]。

在你的視圖 controller 和網格視圖中,導入你的 modalviewcontroller 的 header 文件,符合協議

@interface MyGridViewController : UIViewController <MyViewControllerDelegate>

初始化 Modalview controller 時,將委托設置為 self,並實現 viewControllerWasDismissedOrAnyOtherNameYoudLike 方法。 瞧!

暫無
暫無

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

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