开发者

modalViewController delegate callbacks - HowTo?

开发者 https://www.devze.com 2023-03-20 18:26 出处:网络
I have some view controller, and when I click some button I make modalView (wrapped with UINavigationController) and present it.

I have some view controller, and when I click some button I make modalView (wrapped with UINavigationController) and present it.

DscViewController *enterDescription = [[[DscViewController alloc] init] autorelease];


    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:enterDescription];
    [self presentModalViewController:navControll开发者_如何转开发er animated:YES];
    [navController release];

The question is, how to make my (parent)view controller to be delegate, and when I click on some button at modalViewController (Done for example) to call some method in my parent viewController to dismiss modal and do some savings from modal input?


I don't think that it's good practice to make one controller blame its parent controller to do work that it should handel. You can always use self.parentViewController to dismiss the modal you are currently in.

If for some reason you only handle storage in the parentViewController then you can point your done button action to a method in your current viewController and then use self.parentViewController to trigger the parent method for storage.

or just set your buttons delegate directly to self.parentViewController

[button addTarget:self.parentViewController action:@selector(someMethodInParentViewController) forControlEvents:UIControlEventTouchUpInside];
0

精彩评论

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