开发者

Reload ParentViewController

开发者 https://www.devze.com 2023-01-11 18:09 出处:网络
I have an iPhone application where i\'m showing a settings page using modal view [self presentmodalviewcontroller:tempcontroller animated:yes];

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 u开发者_运维技巧se @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


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

sending data to previous view in iphone


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号