切换到 Xcode 4 后,我认为我可以像在 Xcode 3 中一样构建和运行我的应用程序。
结果我做不到。
Xcode 4 有一种从不显示应用程序视图控制器的有趣方式,这很奇怪。
我可以告诉苹果最终会迫使我们切换,这将导致我的应用程序无法运行。
在挂起之前,它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
如果有人可以在这里帮助我,将不胜感激。