cocoa-touch - 关闭模态视图 Controller 后重新加载 gridView 数据时出现问题

标签 cocoa-touch ios gridview modalviewcontroller

我正在展示一个模态视图 Controller 来显示详细信息。我对其进行了设置,以便对模态视图 Controller 中的信息进行任何更改都会更改其父 View Controller 中的信息。

信息已更改,但当模态视图 Controller 关闭时我无法重新加载 gridView 数据。现在我可以在模态视图 Controller 中关闭模态。一切正常,我只是无法从模态视图 Controller 重新加载 gridView 的数据。

我在某处读到,其中一个选项是创建一个委托(delegate),该委托(delegate)将能够从父 View Controller 中解除模态视图 Controller ,我似乎找不到关于如何进行的示例或教程这。事实上,我知道如何使用委托(delegate),但不太确定如何正确实现委托(delegate)。

任何人都可以在这里指出正确的方向吗?也许有人有更好的选择。我愿意接受任何建议。

最佳答案

如果我理解得很清楚,你想在关闭模态视图 Controller 时重新加载包含在父 View Controller 中的网格。如果是这样,这里是如何:

通过做类似的事情在你的 ModalViewController 中声明一个协议(protocol)

@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 委托(delegate)。

就在您调用 dismissModalViewController:animated: 时,还调用 [delegate viewControllerWasDismissedOrAnyOtherNameYoudLike]。

在你的grid view的view controller中,导入你的modalviewcontroller的头文件,遵守协议(protocol)

@interface MyGridViewController : UIViewController <MyViewControllerDelegate>

当您初始化 Modalview Controller 时,将委托(delegate)设置为 self,并实现 viewControllerWasDismissedOrAnyOtherNameYoudLike 方法。 瞧!

关于cocoa-touch - 关闭模态视图 Controller 后重新加载 gridView 数据时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6114407/

相关文章:

ios - 使用 PinLayout 制作 GridView

java - 当 GridView 中的文本为 null 或为空时如何显示图像,反之亦然?

iphone - 使用CF变量而不是NS变量的好处

ios - Xcode 中的本地化涉及哪些步骤?

ios - UIScrollView内的UILabel上的触摸检测

ios - 如何禁用自定义按钮上的 iOS 默认光泽效果

ios - 游戏中心不保存分数

.net - Databound后如何更改Gridview的标题文本?

ios - iOS,如何为有趣的应用程序划粗线?

cocoa-touch - 手势识别器在 iOS 4.3 中停止工作