简体   繁体   English

关闭模态视图 controller 后重新加载 gridView 数据时出现问题

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

I am presenting a modal view controller to show detailed information.我正在展示一个模态视图 controller 以显示详细信息。 I have it set up so that any change to the information in the modal view controller will change the information in its parent view controller.我进行了设置,以便对模态视图 controller 中信息的任何更改都会更改其父视图 controller 中的信息。

The information is changed, but I cannot manage to reload the gridView data when the modal view controller is dismissed.信息已更改,但当模式视图 controller 被解除时,我无法重新加载 gridView 数据。 Right now I have the action to dismiss the modal inside the modal view controller.现在我可以在模态视图 controller 中关闭模态。 Everything works good, I just can't reload the data for the gridView from the modal view controller.一切正常,我只是无法从模态视图 controller 重新加载 gridView 的数据。

I read somewhere that one of the options is to create a delegate that will be able to dismiss the modal view controller from the parent view controller, I just can't seem to find examples or nice tutorials on how to go by doing this.我在某处读到,其中一个选项是创建一个委托,该委托将能够从父视图 controller 中关闭模态视图 controller,我似乎无法通过执行此操作找到有关如何使用 Z34D1F91FB2E514B8A567A 的示例或很好的教程。 The truth is that I know how to use the delegates, but not quite sure on how to properly implement one.事实是,我知道如何使用代表,但不太确定如何正确实施。

Can anyone please point me in the right direction here?谁能在这里指出我正确的方向? Maybe someone has a better option.也许有人有更好的选择。 I am open to any suggestions.我愿意接受任何建议。

If I understand clearly, you want to reload the grid contained in your parent view controller when you dismiss the modal view controller.如果我清楚地理解,当您关闭模态视图 controller 时,您想重新加载父视图 controller 中包含的网格。 If so, here how:如果是这样,这里如何:

Declare a protocol in your ModalViewController by doing something like通过执行类似的操作在您的 ModalViewController 中声明一个协议

@protocol MyViewControllerDelegate;

@interface MyViewController : UIViewController {

    id<MyViewControllerDelegate>delegate;
    // Your stuff
}

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

@end

@protocol MyViewControllerDelegate <NSObject>

-(void)viewControllerWasDismissedOrAnyOtherNameYoudLike;

@end

And in your.m file, just @synthesize delegate.在您的.m 文件中,只需 @synthesize 委托。

Just when you call dismissModalViewController:animated:, also call [delegate viewControllerWasDismissedOrAnyOtherNameYoudLike].就在你调用dismissModalViewController:animated:时,也调用[delegate viewControllerWasDismissedOrAnyOtherNameYoudLike]。

In your view controller with the grid view, import the header file of your modalviewcontroller, conform to the protocol在你的视图 controller 和网格视图中,导入你的 modalviewcontroller 的 header 文件,符合协议

@interface MyGridViewController : UIViewController <MyViewControllerDelegate>

When you init the Modalview controller, set the delegate to self, and implement the viewControllerWasDismissedOrAnyOtherNameYoudLike method.初始化 Modalview controller 时,将委托设置为 self,并实现 viewControllerWasDismissedOrAnyOtherNameYoudLike 方法。 Voilà!瞧!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM