[英]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.