简体   繁体   English

如何在导航控制器中将数据从一个视图传递到另一个视图

[英]How to pass data from one view to the other in a navigation controller

Okay so I am creating an app for iPhone using a navigation controller and basically what I need to let my addviewcontroller know what the user selected on the addsettingsviewcontroller . 好的,所以我正在使用导航控制器创建一个iPhone应用程序,基本上我需要让我的addviewcontroller知道用户在addsettingsviewcontroller上选择了addsettingsviewcontroller So when the user hits the save button it opens the addviewcontroller and when that is opened it needs to check what value was selected on the previous view. 因此,当用户单击“保存”按钮时,它将打开addviewcontroller,并在打开时需要检查在上一个视图中选择了哪个值。 I can get it to do all that for me but the only problem is that when the save button is pressed and the addviewcontroller loads the navigation bar is no longer there so the user cannot hit the back button and the view's title isn't showing. 我可以为我完成所有操作,但是唯一的问题是,当按下保存按钮并且addviewcontroller加载时,导航栏不再存在,因此用户无法单击后退按钮,并且视图标题也没有显示。 Here is a picture of my storyboard . 这是我的情节提要的图片。

Try this one 试试这个

Addviewcontroller *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"addView"];

controller.status = easy; // select as enum of easy, medium, hard
[self.navigationController pushViewController:controller animated:YES];

Hope this helps you ! 希望这对您有帮助!

If you are using storyboard, let it handles your push or modal as you specified in it. 如果您使用情节提要,请让它按您在其中指定的方式处理您的推送或模式。 Don't disrupt it by using code that upset the flow. 不要使用破坏流程的代码来破坏它。

Declare this in AddViewController.h 在AddViewController.h中声明

@property (nonatomic, strong) NSNumber *status;

Then, in your AddSettingsViewController.m 然后,在您的AddSettingsViewController.m中

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([segue.identifier isEqualToString:@"Add"])
    {
        AddViewController *addViewController = segue.destinationViewController;
        addViewController.status = Selected_Status;
    }
}

Selected_Status can be something like: Selected_Status可能类似于:

[NSNumber numberWithInteger:self.levelSegmentedControl.selectedSegmentIndex];

暂无
暂无

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

相关问题 如何将数据从一个视图控制器传递到导航控制器中嵌入的另一个视图控制器 - How to pass data from one view controller to another view controller which is embedded in navigation controller 如何将数据从一个视图控制器传递到另一个SWIFT - How to pass data from one view controller to the other SWIFT 如何将数据从视图控制器传递到导航控制器,然后传递到另一个视图控制器? - How to pass data from view controller to a navigation controller and then to another view controller? 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS? 将渐变颜色从一个视图控制器传递到另一个视图控制器 - Pass Gradient Color from one view controller to other view controller 如何将数据从一个视图传回到IOS中的其他视图? - How to pass data back from one view to other View in IOS? 如何将数据传递给嵌入在导航控制器中的集合视图控制器 - How to pass data to collection view controller embedded in navigation controller 如何使用委托将数据从一个视图控制器传递到另一个视图控制器? - how to use delegate to pass data to from one View Controller to another? 将数据传递到导航控制器中的另一个视图控制器 - Pass data to another view controller in navigation controller 如何将值从一个视图控制器传递到上一个视图控制器) - How to pass the values from one view controller to previous view controller)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM