我正在尝试从一个 View (一个完全正常的 View )切换到另一个可编程的 View (也是正常的)。这是我现有的代码:
- (IBAction)login:(id)sender {
if([_username.text isEqualToString:name] && [_password.text isEqualToString:pw]) {
DashboardViewController *destinationController = [[DashboardViewController alloc] init];
[self.navigationController pushViewController:destinationController animated:YES];
}else {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Wrong Username or Password!"
message:@"Sorry."
delegate:nil
cancelButtonTitle:@"Okay"
otherButtonTitles:nil, nil];
[message show];
_password.text = nil;
}
}
所以,我想转到我的 DashboardViewController
。如果我尝试此代码,则会显示一个黑色的空 View 。有什么问题吗?
最佳答案
我最近遇到了同样的问题!这是我使用的解决方案:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
DashboardViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"id"];
[self.navigationController pushViewController:viewController animated:YES];
MainStoryboard
应该是 Storyboard的名称,id
应该是您可以在 Storyboard中设置的 View Controller ID。
关于ios - 如何切换到现有的非导航 Controller View 可编程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18495545/