繁体   English   中英

从弹出窗口将UIViewController推送到UINavigationController

[英]Push UIViewController to UINavigationController from a popover

尝试将新的视图控制器推送到现有导航控制器时遇到问题。

我正在尝试的是在按下导航UIBarButtonItem时使UIPopoverController出现,并从该“下拉列表”中选择一个菜单点,该菜单点会将关联的视图控制器推到“主”导航控制器上。

我尝试了以下方法,它给出了一个模态。 但我想推动观点。 在此处输入图片说明 如果选择推式而不是模态,结果如下。

在此处输入图片说明 我还尝试制作了一个自定义UITableViewController (在弹出窗口上),并从中尝试了以下代码:

-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *dash = [storyboard instantiateViewControllerWithIdentifier:@"dash_nav"];
    UIViewController *students = [storyboard instantiateViewControllerWithIdentifier:@"students"];

    if (indexPath.row == 0) {
       [dash pushViewController:students animated:YES];
//     [[dash navigationController] presentViewController:students animated:YES completion:nil];
    }
    NSLog(@"%@", [dash title]);
    NSLog(@"index = %i", indexPath.row);
}

有什么方法可以做我想完成的事情?

这段代码:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *dash = [storyboard instantiateViewControllerWithIdentifier:@"dash_nav"];
UIViewController *students = [storyboard instantiateViewControllerWithIdentifier:@"students"];

正在创建太多新实例。 您应该使用现有的情节提要板( self. storyboard )和现有的导航控制器。 导航控制器需要传递给表视图控制器(您应该使用此视图控制器,因为情节提要没有所需的信息)。 我们将其称为originatingNavigationController ,这是表视图控制器上的新@property

当segue触发显示弹出窗口时,将导航控制器引用设置为目标视图控制器(表视图)。

然后,在didSelectRowAtIndexPath:方法中,您只需实例化students VC并将其推送:

UIViewController *students = [self.storyboard instantiateViewControllerWithIdentifier:@"students"];
[self.originatingNavigationController pushViewController:students animated:YES];

然后表格视图控制器应关闭自身(弹出窗口)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM