我将在下面给出程序的概要,但是,当推动一个新的视图控制器(不是标签栏视图)时,我在步进器上选择一个值,然后单击一个按钮返回。我正在尝试将步进值从 FilterViewController 发送到 FirstViewController。
该程序:
应用程序加载FirstViewController
是选项卡栏控制器的第一个选项卡,屏幕左上角是一个打开 FilterViewController 的按钮(放大镜)。
FilterViewController 有一个步进器、一个标签(显示步进器的值)和一个按钮。您单击按钮,它将步进器的值保存到一个变量中,我需要将它传递给 FirstViewController。
FirstViewController.h(从 FilterViewController 访问的属性)
@interface FirstViewController : UIViewController
{
NSString *passedData;
}
@property(nonatomic, retain) NSString *passedData;
FirstViewController.m(推送新视图控制器的代码,属性也在实现中合成)
- (IBAction)searchOptions:(id)sender {
FilterViewController *ctrl = [[FilterViewController alloc] init];
[UIView transitionFromView:self.view toView:ctrl.view duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:nil];
self.filterViewController = ctrl;
[self.navigationController pushViewController:self.filterViewController animated:NO];
}
FilterViewController.m(保存值并将其传递给 FirstViewController 的代码)
- (IBAction)backToMap:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
FirstViewController *fvc = [storyboard instantiateViewControllerWithIdentifier:@"TabBarController"];
fvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
self.firstViewData = fvc;
fvc.passedData = @"yo";
//firstViewData.passedData = @"hello test test test";
[self presentViewController:fvc animated:YES completion:nil];
}
当它执行这个时它崩溃说:[UITabBarController setPassedData:]: unrecognized selector sent to instance