1

我将在下面给出程序的概要,但是,当推动一个新的视图控制器(不是标签栏视图)时,我在步进器上选择一个值,然后单击一个按钮返回。我正在尝试将步进值从 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

4

2 回答 2

2

假设您的意思是崩溃发生在您的代码的以下行

    fvc.passedData = @"yo";

您可能想检查 fvc 确实是 FirstViewController ,NSLog("%@", fvc);即 IB 中的类是否从 UIViewController 更改为 FirstViewController ?

于 2013-05-31T11:11:55.110 回答
1

看看你的代码。您将TabBarController作为 FirstViewController 的标识符。可能是你弄错了

FirstViewController *fvc = [storyboard instantiateViewControllerWithIdentifier:@"TabBarController"]; // Here check the identifier
fvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

self.firstViewData = fvc;
于 2013-05-31T11:26:13.987 回答