由于我是 IOS 开发的新手,所以我并不真正了解开发 iPhone 应用程序时要使用的所有机制。
在这里,我要做的是在执行 segue 后调用另一个 Controller 。
上下文:
我有我的第一个页面,它基本上包含一个登录页面,带有一个用户/密码系统。我创建了一个 segue,通过单击“提交”按钮调用它。这是代码:
- (IBAction)Connect:(UIButton *)sender
{
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
@"passwordsample", @"usernamesample",
nil];
if ((![[dict allKeys] containsObject:TFLogin.text])) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Login or password incorrect" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
NSLog(@"Connection Not OK");
}
else {
[self performSegueWithIdentifier:@"LoginSegue" sender:sender];
NSLog(@"Connection OK");
}
}
这是 prepareForSegue 函数:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
HomeController *home = (HomeController *) segue.destinationViewController;
home.sentLogin = TFLogin.text;
}
事实是,当我单击“提交”按钮(在登录页面上)时,日志显示已正确找到用户,然后我收到如下错误:
2012-04-30 11:24:44.630 AppName[1066:f803] -[UINavigationController setSentLogin:]: unrecognized selector sent to instance 0x6d73c30
2012-04-30 11:24:44.630 AppName[1066:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setSentLogin:]: unrecognized selector sent to instance 0x6d73c30'
这是 Storyboard:
第二个 NavigationController 将替换为 Tab Bar Controller。但是为了进行一些测试,我放了这个。
有人可以指导我,告诉我我做错了什么和/或给我发送一些关于 Storyboard和导航的最新指南吗?
非常感谢!
最佳答案
从错误的外观来看,segue.destinationViewController 似乎不是您认为的那样。听起来您在组合中有一个导航 Controller 。
如果没有 Storyboard,诊断起来有点困难,但请尝试:
UINavigationController *nav = (UINavigationController*)segue.destinationViewController;
HomeController *home = (HomeController*)nav.topViewController;
如果这不起作用,您可能需要在第二行放置一个断点并查看 nab Controller 以查看 HomeController 在其堆栈中的位置。
关于iphone - IOS 5 - 从另一个 ViewController 调用一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10383729/