我知道有很多关于此事的帖子,但我已经尝试了所有内容,但没有任何效果。所以我试图将两个视图控制器之间的对象传递给嵌入在导航项中的DBKIngredientsViewController。我有一个带有标识符“showIngredientsSegue”的push segue到DBKIngredientsViewController。我收到的错误消息是:
'NSInvalidArgumentException',原因:' - [DBKIngredientsViewController topViewController]:无法识别的选择器发送到实例0x8a92450'
我正在使用的视图控制器嵌入在导航控制器中,我认为它正在搞乱它。这有什么办法?为了清楚起见,DBKViewController已经嵌入在导航控制器中,push segue推送DBKViewController,而不是嵌入它的导航控制器。我尝试过不同的方法,但似乎都没有。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"showIngredientsSegue"]){
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
DBKIngredientsViewController *controller = (DBKIngredientsViewController *)navController.topViewController;
controller.targetRecipe = selectedRecipe;
}
}
答案 0 :(得分:2)
您确定segue.destinationViewController
是UINavigationController
吗?看起来它只是一个DBKIngredientsViewController
所以这应该有效:
DBKIngredientsViewController *controller = (DBKIngredientsViewController *)segue.destinationViewController
此外,如果DBKViewController
已有导航控制器,那么如果您正在推动DBKIngredientsViewController
,则不需要第二个导航控制器。如果您以模态方式显示DBKIngredientsViewController
,则只需要第二个。