gpt4 book ai didi

iphone - AppDelegate 导航错误

转载 作者:行者123 更新时间:2023-11-29 13:42:22 28 4
gpt4 key购买 nike

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

最佳答案

您可以创建一个不带 nib 的“代理”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];

关于iphone - AppDelegate 导航错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8713569/

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