【发布时间】:2011-07-20 10:23:20
【问题描述】:
切换到 Xcode 4 后,我认为我能够像在 Xcode 3 中一样构建和运行我的应用程序。
原来我做不到。
Xcode 4 有一种有趣的方式,即从不显示应用程序的视图控制器,这很奇怪。
我可以告诉 Apple 最终会强制我们切换,这将导致我的应用无法运行。
它在挂起之前到达application:didFinishLaunchingWithOptions:,没有任何错误。最终应用程序在设备上崩溃 - 但在模拟器中永远停留在 Default.png 上。
我想我可以去编辑 application:didFinishLaunchingWithOptions: 方法,实例化视图控制器本身的一个实例并将其添加到窗口中 - 只是发现这也不起作用。
经过无数次失败的尝试——为主视图控制器创建单独的 UIWindows——我决定将它添加到导航控制器中。
然后我很幸运——但只是以最简单的形式。我查看了日志,发现 applicationDidBecomeActive: 已被调用。
但是,像往常一样,显示任何类型的视图都没有这样的运气。
然后我决定看看是否可以在窗口中添加一个具有蓝色背景颜色和一些 UI 元素(按钮、标签等)的 UIView,看看是否可行。
有趣的是它确实做到了。
但是为什么不用于主视图控制器呢?在 Xcode 4 中,我没有一次成功地让它运行我的应用程序(即使在构建后打开它也会失败)。我尝试将编译器更改为与 Xcode 3 中相同的编译器,但没有成功。
我真的很困惑为什么应用程序的视图控制器不会显示。
对于任何想尝试一下它为什么不起作用的人,我们将不胜感激。
这是 AppDelegate 的代码,如果您需要视图控制器的代码,我可以将其粘贴在这里,但它超过 2000 行。
无论如何,这是 .m 文件:
#import "DocumentationAppDelegate.h"
#import "DocumentationViewController.h"
@implementation DocumentationAppDelegate
@synthesize window;
@synthesize viewController;
@synthesize navigationController;
- (void)applicationWillEnterForeground:(UIApplication *)application {
NSLog(@"In method %@, which is in class %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class]));
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(@"In method %@, which is in class %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class]));
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"In method %@, which is in class %@.", NSStringFromSelector(_cmd), NSStringFromClass([self class]));
DocumentationViewController *vc = [[DocumentationViewController alloc] init];
UINavigationController *controller = [[UINavigationController alloc] initWithRootViewController:vc];
controller.navigationBarHidden = YES;
UIWindow *win = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[win addSubview:controller.view];
[win makeKeyAndVisible];
return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
和.h
#import <UIKit/UIKit.h>
@class DocumentationViewController;
@interface DocumentationAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
DocumentationViewController *viewController;
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet DocumentationViewController *viewController;
@end
如果有人可以在这里帮助我,将不胜感激。
【问题讨论】:
标签: ios xcode uiview uiviewcontroller rootview