重新加载ParentViewController
我有一个 iPhone 应用程序,其中使用模态视图显示设置页面
[selfpresentmodalviewcontroller:tempcontrolleranimated:yes];
当用户完成设置后,他可以返回上一页。
[self.dismissmodalviewcontroller animated:YES];
现在我想当用户从设置页面返回时重新加载我的主页。我读到了一些我应该使用 @protocol and delegate
来实现这一点的内容。我已经浏览了网上有关此主题的一些教程。但我无法做到这一点。我对 @protocol 和 delegate
一无所知,因为我是 iPhone 开发的新手。
请帮助我提供一些好的教程。如果您可以向我推荐任何包含我的需求的逐步描述的链接,那就太好了。
期待您的帮助......
提前致
谢乔伊
I have an iPhone application where i'm showing a settings page using modal view
[self presentmodalviewcontroller:tempcontroller animated:yes];
When the user finishes the settings he can come back to the previous page.
[self.dismissmodalviewcontroller animated:YES];
Now i want to reload my main page when user comes back from the settings page. I read some where that i should use @protocol and delegate
for that to happen.I have gone through some of the tutorials on the web on this topic. But i'm not been able to do that.I have no knowledge on @protocol and delegate
as i'm new to the iPhone development.
Please help me with some good tutorials. It would be greate if you can suggest me any link having step by step description of my need.
Looking forward to your help....
Thanks in advance
Joy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一个更简单的选择是使用 NSNotificationCenter。看看这个
将数据发送到 iPhone 中的上一个视图
Another easier option would be to use the
NSNotificationCenter
. Have a look at thissending data to previous view in iphone
乔伊,
假设您有一个视图控制器正在呈现另一个模态 - 称之为“根”。
模态称为“Modal”,
“Root”会说,
那么Root如何知道何时关闭Modal呢?做到这一点的最好方法是为此行为制定一个“协议”。
在 Modal 的头文件中,会有这样的代码:
然后,应该有一个 modal 的实例变量:
带有属性:
这使得每次 Modal 向其属性“delegate”发送消息时,我们都知道它有方法 -(void)modalViewControllerDidFinish:
假设 Modal 中有一个您想要关闭它的按钮。该按钮只需要调用
[delegate modalViewControllerDidFinish:self];
在 root 的头文件中,您可以像这样声明该类:
并且您可以像这样实现 modalViewControllerDidFinish 方法:
这有意义吗?
Joy,
Let's say you have a viewController that is presenting another modally - call it "root".
The modal is called "Modal"
"Root" is going to say,
So how does Root know when to dismiss Modal? The best way to do this, is to make a "protocol" for this behavior.
In the header file for Modal, there would be code like this:
Then, there should be an instance variable for modal:
with a property:
This makes it so every time Modal sends a message to it's property 'delegate', we know that it has the method -(void)modalViewControllerDidFinish:
So let's say there's a button inside Modal that you want to close it. The button simply needs to call
[delegate modalViewControllerDidFinish:self];
In the header file for root, you declare the class like this:
And you implement the method modalViewControllerDidFinish like this:
Does this make sense?