Ios 如何在导航控制器中将数据从一个视图传递到另一个视图
好的,我正在使用导航控制器为iPhone创建一个应用程序,基本上我需要让我的Ios 如何在导航控制器中将数据从一个视图传递到另一个视图,ios,iphone,objective-c,uinavigationcontroller,Ios,Iphone,Objective C,Uinavigationcontroller,好的,我正在使用导航控制器为iPhone创建一个应用程序,基本上我需要让我的addviewcontroller知道用户在addsetingsviewcontroller上选择了什么。因此,当用户点击save按钮时,它会打开addviewcontroller,当打开该按钮时,它需要检查在上一个视图中选择了什么值。我可以让它为我完成所有这些,但唯一的问题是,当按下“保存”按钮并且加载addviewcontroller时,导航栏不再存在,因此用户无法点击“后退”按钮,视图的标题也不显示。 这是我的一张
addviewcontroller
知道用户在addsetingsviewcontroller
上选择了什么。因此,当用户点击save按钮时,它会打开addviewcontroller,当打开该按钮时,它需要检查在上一个视图中选择了什么值。我可以让它为我完成所有这些,但唯一的问题是,当按下“保存”按钮并且加载addviewcontroller
时,导航栏不再存在,因此用户无法点击“后退”按钮,视图的标题也不显示。
这是我的一张照片。试试这张
Addviewcontroller *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"addView"];
controller.status = easy; // select as enum of easy, medium, hard
[self.navigationController pushViewController:controller animated:YES];
希望这对你有帮助 如果您使用的是故事板,请让它按照您在其中指定的方式处理推送或模式。不要使用打乱流程的代码来破坏它 在AddViewController.h中声明此项
@property (nonatomic, strong) NSNumber *status;
然后,在AddSettingsViewController.m中
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"Add"])
{
AddViewController *addViewController = segue.destinationViewController;
addViewController.status = Selected_Status;
}
}
所选的_状态可以类似于:
[NSNumber numberWithInteger:self.levelSegmentedControl.selectedSegmentIndex];
请分享一些代码。这很有效!!!非常感谢,我已经连续三天在做这个了!