OGeek|极客世界-中国程序员成长平台

标题: ios - 从外部委托(delegate)推送 View Controller [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:40
标题: ios - 从外部委托(delegate)推送 View Controller

我有两个类; MasterView 这是一个 UIViewController 显示我的 TableView 和 MyClass 由于各种原因充当 TableView 的委托(delegate)和数据源。选择单元格时,我需要推送 View Controller (DetailView)。如何从 MyClass 推送 View ?这就是我真正拥有的一切:

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath
{

if (!detailViewController) {
    detailViewController = [[DetailViewController alloc] initWithNibName"DetailViewController" bundle:nil];
}

//Somehow push detailViewController
}



Best Answer-推荐答案


有几种方法可以做到这一点。我假设您已经将 Masterview 嵌入到 UINavigationController 中,对吗?

您可以通过传递对 Masteriew 的引用来访问它,然后使用:

[masterView.navigationController pushViewController:detailViewController animated:YES];

如果您的 Masterview 以某种方式与您的 App 的 Delegate 相关并且您想要访问它,您也可以使用以下行:

MainClass *appDelegate = (MainClass *)[[UIApplication sharedApplication] delegate];

关于ios - 从外部委托(delegate)推送 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17002499/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4