gpt4 book ai didi

objective-c - 奇怪的 pushViewController 行为

转载 作者:行者123 更新时间:2023-12-04 05:12:06 24 4
gpt4 key购买 nike

我的应用开始于 LoginViewController .
登录 View 有一个“注册”按钮,代码如下所示。
如果我点击注册,当应用程序启动时,什么也没有发生。但是,如果我登录并注销,则注册按钮可以正常工作。

发生这种情况应该是什么问题?

应用委托(delegate):

...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

//Load View Controllers;

self.vcClubs = [[[ClubsViewController alloc] init] autorelease];
self.vcParties = [[[PartiesViewController alloc] init] autorelease];
self.vcEditProfile = [[[EditProfileViewController alloc] init] autorelease];

self.navClubs = [[[UINavigationController alloc] initWithRootViewController:self.vcClubs] autorelease];
self.navClubs.navigationBarHidden = YES;

self.navParties = [[[UINavigationController alloc] initWithRootViewController:self.vcParties] autorelease];
self.navParties.navigationBarHidden = YES;

// Load Login View
UIViewController *loginView = [[[LoginViewController alloc] init] autorelease];
self.window.rootViewController = loginView;
[self.window makeKeyAndVisible];

return YES;
}
...
- (void)login
{
self.vcMenu = [[[MenuViewController alloc] init] autorelease];
self.vcLocationMenu = [[[LocationMenuViewController alloc] init] autorelease];
self.mainController = [[[MainViewController alloc] init] autorelease];
self.mainController.leftViewController = self.vcMenu;
self.mainController.rightViewController = self.vcLocationMenu;

[self.mainController setMainViewController:self.navParties];
[self.mainController showMainViewControllerAnimated:YES];

self.window.rootViewController = self.mainController;

CATransition *transition = [[[CATransition alloc] init] autorelease];
transition.duration = 1;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromBottom;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.window.layer addAnimation:transition forKey:@"login"];
}
...

登录 Controller .php:
...
- (IBAction)onTapSignupButton:(id)sender
{
RegisterViewController *controller = [[[RegisterViewController alloc] init] autorelease];
[self.navigationController pushViewController:controller animated:YES];
NSLog(@"%@", self.navigationController);
}
...

在应用启动时返回 NSLOG:
2013-02-18 02:18:29.986 App[32652:c07] (null)

最佳答案

它可能看起来很奇怪。但我犯了同样的错误。希望对你有帮助。。

检查您是否在 AppDelegate 中初始化了 UInavigationController。如果是,我不知道你为什么得到这个......如果不是,请尝试以下代码

RegisterViewController *controller = [[[RegisterViewController alloc] init] autorelease];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:controller]
[self.navigationController pushViewController:controller animated:YES];

根据您编辑的代码
 // Load Login View
UIViewController *loginView = [[[LoginViewController alloc] init] autorelease];
UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:loginView]
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];

快乐编码!

关于objective-c - 奇怪的 pushViewController 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14783216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com