segue无法正常工作导致应用崩溃

时间:2014-05-07 01:51:23

标签: ios objective-c runtime-error segue unrecognized-selector

我的代码在segue上打破了。 segue最初是模态的,我试图改变它以推动但它仍然无法工作我的代码如下:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    if ([[segue identifier ] isEqualToString:@"detailLoanSeg"]){
    detailLoan *theController=[segue destinationViewController];
    theController.time=_time;
    theController.cuurLoan=_cuurLoan;
    theController.currName=_currName;
   }
}

,xcode中的错误是:

 014-05-07 04:38:11.257 LoanCalc[1561:a0b] -[UIViewController setTime:]: 
 unrecognized selector sent to instance 0xa05f1f0  
 2014-05-07 04:38:11.266 LoanCalc[1561:a0b] *** Terminating app due to uncaught 
 exception 'NSInvalidArgumentException', reason: '-[UIViewController setTime:]: 
 unrecognized selector    sent to instance 0xa05f1f0'

2 个答案:

答案 0 :(得分:4)

看起来,在故事板中,您忘记指示目标视图控制器的自定义类。在故事板中,选择该目标VC,单击右侧的第三个检查器并将其自定义类设置为" detailLoan" (违反了类命名约定。)

错误是您的目标vc是通用的UIViewController,它自然不会实现setTime:方法。

答案 1 :(得分:-1)

您确定目标类是View Controller而不是UINavigationController吗?放置断点并检查控制器类是什么。还要确保Storyboard中的视图控制器的类设置从默认的UIViewController到自定义子类。这几乎肯定是这两个问题中的一个。