我有一个在 View 之间使用 UINavegationController 的项目:
我正在使用导航 Controller ,因为我正在使用模态呈现(翻转)
但我的问题是我试图将 NSString 对象传递给 ViewControllerB: 代码:
- (IBAction)goToB:(id)sender {
[self performSegueWithIdentifier:@"goToB" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"goToB"]) {
BViewController *vc = (BViewController*)[segue destinationViewController];
vc.commigFromA = @"I'm going to B!";
}
}
但是我收到了这个错误:
-[UINavigationController setCommigFromA:]: unrecognized selector sent to instance 0x7ff1c4830c00
你们中有人知道这个错误的原因或解决方法吗?
非常感谢你的帮助
最佳答案
它崩溃了,因为segue上的destinationViewController
实际上是一个UINavigationController
,而不是BViewController
和UINavigationControllers
不知道属性 comingFromA
。您可以像这样替换 prepareWithSegue
来测试这个理论:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"goToB"]) {
UINavigationController *nvc = (UINavigationController*)[segue destinationViewController];
BViewController *vc = (BViewController*)nvc.viewControllers[0];
vc.commigFromA = @"I'm going to B!";
}
}
关于iOS:将对象传递给 viewController 错误:无法识别的选择器已发送至实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40619261/