繁体   English   中英

AppDelegate导航错误

[英]AppDelegate Navigation error

- (void)applicationDidFinishLaunching:(UIApplication *)application {   
    NSError *error = nil;
    NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
    NSString *str =  [SFHFKeychainUtils getPasswordForUsername:username andServiceName:@"mybibleapp" error:&error];
    NSLog(@"previous un");
    NSLog(@"%@", str);
    if(str != nil)
    {
      main_page *detailViewController = [[main_page alloc] initWithNibName:@"main_page" bundle:nil];
      // Pass the selected object to the new view controller.
      // detailViewController.localStringtextnote = localStringtextnote;
      [self.navigationController pushViewController:detailViewController animated:YES];
      [detailViewController release];
    }

当我将这段代码导航到main_page时,它显示一个错误,即property navigationController not found on object of appdelegate因此我将这段代码插入了上面

 main_page  *log = [[main_page alloc] initWithNibName:@"main_page" bundle:nil];
 [window addSubview:tabController.view];
 [window addSubview:log.view];
 [window makeKeyAndVisible];

该页面被重定向到main_page,但是这种方式没有任何作用。 main_page中没有导航有效,我无法从main_page重定向任何页面。 那么我该怎么做才能解决这些错误。

您可以创建一个不带笔尖的“代理” viewController,将其加载到MainWindow的navigationController中,然后在代理的viewDidLoad中执行以下操作

NSError *error = nil;
NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:@"username"];
NSString *str =  [SFHFKeychainUtils getPasswordForUsername:username andServiceName:@"mybibleapp" error:&error];
NSLog(@"previous un");

NSLog(@"%@", str);

UIViewController *controller;

if (!error && nil != str) {
    controller = [[DetailViewController alloc] init];
} else {
    controller = [[LoginViewController alloc] init];
}
[[self navigationController] pushViewController:controller animated:YES];
[controller release];

初始页面加载通常在MainWindow.xib nib中处理。 您不必手动加载它。

尝试从模板创建一个新项目,然后查看并设置appDelegate和MainWindow.xib。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM