iphone - modalViewController 委托(delegate)回调 - 如何?

标签 iphone objective-c ios uiviewcontroller modalviewcontroller

我有一些 View Controller ,当我点击某个按钮时,我制作了 modalView(用 UINavigationController 包装)并呈现它。

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


    UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:enterDescription];
    [self presentModalViewController:navController animated:YES];
    [navController release];

问题是,如何使我的(父) View Controller 成为委托(delegate),以及当我单击 modalViewController 上的某个按钮(例如完成)以调用我的父 viewController 中的某些方法以关闭模态并从中节省一些费用模态输入?

最佳答案

我认为让一个 Controller 责怪其父 Controller 去做它应该处理的工作并不是一个好习惯。您始终可以使用 self.parentViewController 关闭当前所在的模式。

如果出于某种原因你只处理 parentViewController 中的存储,那么你可以将你的 done 按钮操作指向你当前 viewController 中的一个方法,然后使用 self.parentViewController 来触发存储的父方法。

或者直接将按钮委托(delegate)给 self.parentViewController

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

关于iphone - modalViewController 委托(delegate)回调 - 如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6726755/

相关文章:

iphone - 在多台 Mac 上开发 iPhone 应用程序

iphone - Adhoc App无法安装在设备上

ios - UITableViewCell 重用自定义 UIView 作为组件导致 "caching"问题

ios - 如何访问 XLFormRowDescriptor 的占位符文本颜色

iphone - UIWebview 加载安全页面缓慢

iOS,自定义单元格中特定元素的alertView

javascript - 如果在已获得焦点时单击文本输入,如何执行某些操作 - 在 iPhone 上

iphone - TableView :commitEditingStyle:forRowAtIndexPath how to stop delete button from showing on some cells

ios - 当文本字段没有 IBOutlet 时关闭键盘

ios - 创建 IOS 应用程序教程时遇到问题