Iphone 重新加载ParentViewController
我有一个iPhone应用程序,其中我使用模式视图显示设置页面Iphone 重新加载ParentViewController,iphone,parentviewcontroller,Iphone,Parentviewcontroller,我有一个iPhone应用程序,其中我使用模式视图显示设置页面 [自我呈现ModalViewController:tempcontroller动画:是] 用户完成设置后,可以返回上一页 [self.dismissmodalviewcontroller animated:YES]; 现在我想在用户从设置页面返回时重新加载主页。我读了一些我应该使用@协议和委托来实现这一点的文章。我已经阅读了一些关于这个主题的网上教程。但我没能做到这一点。我对@协议和委托不了解,因为我是iPhone开发的新手 请帮我
[自我呈现ModalViewController:tempcontroller动画:是]代码>
用户完成设置后,可以返回上一页
[self.dismissmodalviewcontroller animated:YES];
现在我想在用户从设置页面返回时重新加载主页。我读了一些我应该使用@协议和委托来实现这一点的文章。我已经阅读了一些关于这个主题的网上教程。但我没能做到这一点。我对@协议和委托不了解,因为我是iPhone开发的新手
请帮我学一些好的教程。这将是伟大的,如果你能建议我的任何链接有一步一步描述我的需要
期待您的帮助
提前谢谢
乔伊乔伊
假设您有一个viewController,它以模态的方式呈现另一个视图-称之为“根”
模态称为“模态”
“根”会说
[self presentModalViewController:Modal];
那么,Root如何知道何时关闭Modal呢?做到这一点的最佳方法是为这种行为制定一个“协议”
在Modal的头文件中,会有如下代码:
@protocol ModalViewDelegate <NSObject>
-(void)modalViewControllerDidFinish:(UIViewController *)viewController;
@end
@class Root : UIViewController <ModalViewDelegate>
-(void)modalViewControllerDidFinish:(UIViewController *)controller {
// any action you need to take on controller
[self dismissModalViewControllerAnimated:YES];
}
您实现的方法是modalviewcontrollerdifinish,如下所示:
@protocol ModalViewDelegate <NSObject>
-(void)modalViewControllerDidFinish:(UIViewController *)viewController;
@end
@class Root : UIViewController <ModalViewDelegate>
-(void)modalViewControllerDidFinish:(UIViewController *)controller {
// any action you need to take on controller
[self dismissModalViewControllerAnimated:YES];
}
这有意义吗?另一个更简单的选择是使用NSNotificationCenter
。看看这个
NSNotification center在语义上将模态视图与根视图分离。。。这是没有意义的,因为这是一对一的关系,一方是另一方的明确代表。谢谢格里尔莫的详细回答。我已经实现了它,但它给了我一个错误-[UIView ModalviewcontrollerdFinish:]:发送到实例0xd38280的无法识别的选择器不知道为什么??您必须说Modal.delegate=root;确保在根上实现了该方法。做一些阅读。这是苹果公司推荐的解决方案。