重新加载ParentViewController

发布于 2024-09-14 12:56:08 字数 500 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅笑轻吟梦一曲 2024-09-21 12:56:08

另一个更简单的选择是使用 NSNotificationCenter。看看这个

将数据发送到 iPhone 中的上一个视图

Another easier option would be to use the NSNotificationCenter. Have a look at this

sending data to previous view in iphone

梦初启 2024-09-21 12:56:08

乔伊,

假设您有一个视图控制器正在呈现另一个模态 - 称之为“根”。

模态称为“Modal”,

“Root”会说,

[self presentModalViewController:Modal];

那么Root如何知道何时关闭Modal呢?做到这一点的最好方法是为此行为制定一个“协议”。

在 Modal 的头文件中,会有这样的代码:

@protocol ModalViewDelegate <NSObject>

-(void)modalViewControllerDidFinish:(UIViewController *)viewController;

@end

然后,应该有一个 modal 的实例变量:

id<ModalViewDelegate> delegate;

带有属性:

@property (assign) id<ModalViewDelegate> delegate;

这使得每次 Modal 向其属性“delegate”发送消息时,我们都知道它有方法 -(void)modalViewControllerDidFinish:

假设 Modal 中有一个您想要关闭它的按钮。该按钮只需要调用 [delegate modalViewControllerDidFinish:self];

在 root 的头文件中,您可以像这样声明该类:

@class Root : UIViewController <ModalViewDelegate>

并且您可以像这样实现 modalViewControllerDidFinish 方法:

-(void)modalViewControllerDidFinish:(UIViewController *)controller {
    // any action you need to take on controller
    [self dismissModalViewControllerAnimated:YES];
}

这有意义吗?

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,

[self presentModalViewController:Modal];

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:

@protocol ModalViewDelegate <NSObject>

-(void)modalViewControllerDidFinish:(UIViewController *)viewController;

@end

Then, there should be an instance variable for modal:

id<ModalViewDelegate> delegate;

with a property:

@property (assign) id<ModalViewDelegate> delegate;

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:

@class Root : UIViewController <ModalViewDelegate>

And you implement the method modalViewControllerDidFinish like this:

-(void)modalViewControllerDidFinish:(UIViewController *)controller {
    // any action you need to take on controller
    [self dismissModalViewControllerAnimated:YES];
}

Does this make sense?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文