当前ModalViewController问题
我正在编写一个 iPhone 应用程序,您需要在开始时进行身份验证。 因此,一旦应用程序在 viewDidLoad 中加载,我就会分配一个负责注册和身份验证的 UIViewController,并像这样呈现它:
- (void)viewDidLoad {
[super viewDidLoad];
self.registerProfile = [[[RegisterViewController alloc] initWithNibName:@"RegisterProfile" bundle:nil] autorelease];
[self presentModalViewController:self.registerProfile animated:YES];
[self.registerProfile release];
}
由于某种原因,当从 viewDidLoad 调用它时它不起作用。 但是如果我在该视图上创建一个按钮并附加上面相同的代码,当我单击它时, 它有效并呈现了视图。
知道为什么它在 viewDidLoad 上不起作用而用按钮却可以吗?
我还测试了一个名为 NavBar 的 Apple 示例。当单击按钮时,它使用presentModalViewController 呈现一个视图,当我将其添加到ViewDidLoad 时,它不起作用!
我在这里缺少什么?我希望该过程在视图加载时自动进行,而不是通过按按钮来实现。
谢谢!
I'm writing an iPhone application which you need to authenticate at the beginning.
Therefore as soon as the application load in the viewDidLoad i allocate a UIViewController which is in-charge of registration and authentication and i present it like so:
- (void)viewDidLoad {
[super viewDidLoad];
self.registerProfile = [[[RegisterViewController alloc] initWithNibName:@"RegisterProfile" bundle:nil] autorelease];
[self presentModalViewController:self.registerProfile animated:YES];
[self.registerProfile release];
}
For some reason it does not work when it is called from viewDidLoad.
But if i create a button on that view and append the same code above, when i click it,
it works and the view is presented.
Any idea why it does not work on viewDidLoad and with a button it does ?
I also tested an Apple example called NavBar. When a button is clicked it present a view using the presentModalViewController, when i added it to the ViewDidLoad it did not work!
What am i missing here ? I want that process to be automatically when the view loads and not by a push of a button.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
经过尝试和搜索深层网络后,我找到了解决方案。
将相同的代码放入 viewDidAppear 中,而不是 viewDidLoad 中,因为视图尚未初始化。
After playing around and searching the deep web I have found the solution.
Put the same code inside viewDidAppear and not viewDidLoad since the view cannot be initialized yet.
我碰巧有一个与上面几乎完全相同的代码,并且运行良好。尝试这样做:
I happen to have a code that's almost exactly the same as above and it works fine. Try to do this: