iphone - 呈现模态视图总是失败

标签 iphone ios objective-c modalviewcontroller uistoryboard

我不断收到此警告,无论我尝试什么,我都不确定如何解决它。

Attempt to present <LoginViewController: 0x1f0b5010> on <ViewController: 0x1dda1670> whose view is not in the window hierarchy!

我的 Storyboard中没有segue,因为我以编程方式调用模态视图:
//Load Login View if no username is found
NSLog(@"No username found");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
LoginViewController *loginView = (LoginViewController *)
[storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
[self presentViewController:loginView animated:YES completion:nil];

这是我的 Storyboard的图像:

enter image description here

谢谢!!!

最佳答案

如果您尝试在 ViewDidload 中呈现 View ,会产生错误。

如果你想使用它,你可以使用 performselector而不是延迟调用此代码。

关于iphone - 呈现模态视图总是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16395680/

相关文章:

objective-c - 为什么类型为 id<someProtocol> 的变量不能接收 id<otherProtocol> 的参数,即使 'otherProtocol' 符合 'someProtocol' ?

ios - UIView transitionWithView 不起作用

ios - 如何停止覆盖数据

iphone - 使用 Core Graphics 绘制部分图像或对角剪裁

iphone - 隐藏键盘

iphone - 无法从 SQLite 数据库 iOS6.0 检索数据

ios - 如何在 UITableview 单元格中正确显示分隔的 JSON 数据?

objective-c - 使用 open() 保证文件权限与使用 NSData 文件写入方法写入的文件的权限相同

c++ - 如何在 Xcode 中将 C++ 转换为 Objective C 以编译 Box2D?

ios - 检查 UITextfield 只有字母没有数值