gpt4 book ai didi

iOS 无法加载 View

转载 作者:行者123 更新时间:2023-11-28 22:35:24 26 4
gpt4 key购买 nike

我正在尝试使用 iOS 5.0 通过触摸按钮从一个 View 导航到另一个 View 。

我正在使用的代码

- (IBAction)Actionlogin:(id)sender {
NSLog(@" login button has been pressed");
NSLog(@"In init");
test_details *aSecondPageController=[[test_details alloc]initWithNibName:@"test_details" bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:NO];
}

我有两个 xib 文件 test_details_iPhone.xibtest_details_iPad.xib

在我的 testdetails.m 中

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSLog(@"it is coming here in second view");
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self) {
// Custom initialization
}
NSLog(@"it has been returned ");
return self;


}

日志

2013-04-25 11:06:17.191 app_gototest[3067:207]  login button has been pressed
2013-04-25 11:06:17.194 app_gototest[3067:207] In init
2013-04-25 11:06:17.195 app_gototest[3067:207] it is coming here in second view
2013-04-25 11:06:17.196 app_gototest[3067:207] it has been returned

View 未加载到 View 中。我想我遗漏了什么。

application:didFinishLaunchingWithOptions:appDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}

** 我正在尝试 Jasper Blue 的方法**

argc    int 1
argv char ** 0xbfffed2c
*argv char * 0xbfffee44

在 appDeleagte.m 中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController* navigationController;
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];
}
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}

最佳答案

您的代码看起来不错,所以 self.navigationController 一定是 nil。 . .您是否设置了导航 Controller ?

要让您的代码正常工作,您当前的 UIViewController 需要包含在 UINavigationController 中。 . .您可以将 UINavigationController 设置为应用程序委托(delegate)中的 Root View Controller ,如下所示:

{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController* navigationController;
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
navigationController = [UINavigationController alloc] initWithRootViewController:viewController];
} else {
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
navigationController = [UINavigationController alloc] initWithRootViewController:viewController];
}
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}

注意:您可以稍微清理上面的代码,但您明白了,您必须将 Root View Controller 设置为导航 Controller ,如下所示:

 self.window.rootViewController = navigationController;

如果您愿意,您也可以创建一个自定义 Root View Controller ,但以上内容可以让您实现您想要做的事情 - UINavigationController 将用作整个应用程序的导航系统。

关于iOS 无法加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16207184/

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