2

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

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

应用委托:

...
- (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"];
}
...

登录控制器.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)
4

4 回答 4

2

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

检查您是否在 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];

快乐编码!

于 2013-02-18T04:31:57.040 回答
1

似乎您第一次尝试时,LoginViewController 没有被包装在导航控制器中。我会检查登录/注销周期是否将登录控制器放入导航堆栈,并查看为什么在第一次出现登录时没有发生这种情况

于 2013-02-09T00:01:30.567 回答
0

试试这个,

RegisterViewController *controller = [[[RegisterViewController alloc] initWithNibName:@"RegisterViewController" bundle:nil];

[self.navigationController pushViewController:controller animated:YES];
于 2013-02-18T04:57:34.563 回答
0
RegisterViewController *controller = [[[RegisterViewController alloc] init] autorelease];
[self.navigationController pushViewController:controller animated:YES];

由于 Objective C 内存管理,您的代码不正确 首先,您应该检查您的导航控制器是否不为零。然后^正确的代码看起来像

RegisterViewController *controller = [[RegisterViewController alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
于 2013-02-18T05:04:54.707 回答