繁体   English   中英

iOS-如何将导航控制器添加到项目?

[英]ios-How do I add a navigation controller to a project?

我有一个项目,并且在维护导航控制器(通过接口构建器添加)时遇到了麻烦。 我要建立一个层次结构,因为它是说视图未添加到窗口层次结构中。 我可以使用performSegueWithIdentifier在一个视图之间切换,但是第二次使用不起作用。 问题是它不允许我从一种视图移动到另一种视图。 我已经阅读过有关混淆appdelegate或添加performForSegue的内容,但是我不知道如何使用它。

如果我有3个类似1-> 2-> 3的视图,有什么建议吗? 1和2将具有performSegueWithIdentifier。

谢谢,麻烦您了!

这是我的故事板: http ://s1370.photobucket.com/user/sean_cleveland1/media/Untitled_zpsc9022523.png.html?o =0

这是我的performSegueWithIdentifier函数:

//Used in FirstVC.
[self performSegueWithIdentifier: @"firstToSecond" sender: self];
//Used in SecondVC... this doesn't work!
[self performSegueWithIdentifier: @"secondToThird" sender: self];

您的故事板

只需控制+从“ Pop to Main Screen” UIButton拖动到退出(场景底部的绿色按钮),选择在第一个屏幕中声明为标题为“ Main”的展开方法,例如

-(IBAction)customUnwind:(UIStoryboardSegue *)sender
{

NSLog(@"Unwind successful");

}

首先定义您的第三个视图标识符

在此处输入图片说明

- (void)segue
{

    [self performSegueWithIdentifier:@"mySegue" sender:self];

}

仅在任何条件或操作下使用以下方法

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if([[segue identifier] isEqualToString:@"mySegue"]) {


    }
}

我为您创建了一个简单的示例项目

https://github.com/iDevAndroid/NavigationSample

在此处输入图片说明

试试这个。 因为您在下一行之后执行模型事务,所以您正在使用以关闭模型。

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{



    [self becomeFirstResponder];
        [self dismissViewControllerAnimated:YES completion:^{
[self emailDelivaryedSuccessfully];
];

}



-(void)emailDelivaryedSuccessfully{


        [self performSegueWithIdentifier: @"secondToThird" sender: self];
}

您不需要使用performSegueWithIdentifier:如果在Storyboard中进行操作,只需在代码中注释“ performSegueWithIdentifier:prepareForSegue:方法的代码,然后尝试。 如果您正在使用performSegueWithIdentifier:则还需要实现prepareForSegue:方法。 恩。

[self performSegueWithIdentifier: @"firstToSecond" sender: self];

// prepareforsegue方法

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if([[segue identifier] isEqualToString:@"firstToSecond"]) {

        SecondViewController *destinationController = [segue destinationViewController];
       //set data if any
    }
}

暂无
暂无

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

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