当前ModalViewController问题

发布于 2024-10-09 20:33:49 字数 715 浏览 4 评论 0原文

我正在编写一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城之時有危險 2024-10-16 20:33:49

经过尝试和搜索深层网络后,我找到了解决方案。
将相同的代码放入 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.

氛圍 2024-10-16 20:33:49

我碰巧有一个与上面几乎完全相同的代码,并且运行良好。尝试这样做:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.registerProfile = [[[RegisterViewController alloc] initWithNibName:@"RegisterProfile" bundle:nil] autorelease];
    registerProfile.delegate = self; //set delegate as yourself
    [self presentModalViewController:self.registerProfile animated:YES];
    //[self.registerProfile release]; //don't worry about releasing it, it's been autoreleased.
 }

I happen to have a code that's almost exactly the same as above and it works fine. Try to do this:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.registerProfile = [[[RegisterViewController alloc] initWithNibName:@"RegisterProfile" bundle:nil] autorelease];
    registerProfile.delegate = self; //set delegate as yourself
    [self presentModalViewController:self.registerProfile animated:YES];
    //[self.registerProfile release]; //don't worry about releasing it, it's been autoreleased.
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文