我知道有很多关于此的帖子,但我已经尝试了所有方法,但没有任何效果。因此,我尝试将两个 View Controller 之间的对象传递给嵌入在导航项中的 DBKIngredientsViewController。我有一个带有标识符“showIngredientsSegue”的推送 segue 到 DBKIngredientsViewController。我收到的错误信息是:
'NSInvalidArgumentException', reason: '-[DBKIngredientsViewController topViewController]: unrecognized selector sent to instance 0x8a92450'
我要连接到的 View Controller 嵌入在导航 Controller 中,我认为它搞砸了。有什么办法解决这个问题?需要明确的是,DBKViewController 已经嵌入到导航 Controller 中,而 push segue 推送的是 DBKViewController,而不是嵌入它的导航 Controller 。我尝试过不同的方法,但似乎都不起作用。
-(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;
}
}
最佳答案
你确定 segue.destinationViewController
是一个 UINavigationController
吗?它似乎只是一个 DBKIngredientsViewController
所以这应该可以工作:
DBKIngredientsViewController *controller = (DBKIngredientsViewController *)segue.destinationViewController
此外,如果 DBKViewController
已经有一个导航 Controller ,那么如果您要推送 DBKIngredientsViewController
,则不需要第二个。如果您以模态方式显示 DBKIngredientsViewController
,则只需要第二个。
关于ios - 使用 Storyboard segue iOS 将数据传递给 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19739037/