AppDelegate导航错误

时间:2012-01-03 14:15:46

标签: iphone ios

- (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中的任何页面。那么我该怎么做才能解决这些错误。

2 个答案:

答案 0 :(得分:1)

你可以创建一个没有nib的“proxy”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];

答案 1 :(得分:0)

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

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