xcode 4.2 不再支持 Window-Based Application 的解决办法(转载)

来源:互联网 发布:手机虚拟实验室软件 编辑:程序博客网 时间:2024/06/06 01:54

xcode 4.2 不再支持 Window-Based Application 的解决办法:
     1.创建空项目 Empty Application。(在Xcode4.2下创建的这个空项目不再有MainWindow.xib文件了。)
     2.Ctrl+N,创建User Interface下面的Window(选择“iOS->User Interface->Window),命名成MainWindow.xib。
     3.File Owner修改成UIApplication。(即调出show identity inspector面板,将file's Owner的属性Custom Class中将class改为UIApplication。)


     4.从Library库中,拖个Object出来添加,并修改类为Delegate的那个类,最开始自动生成的那个。(即将新添加的Object的Class改为AppDelegate)



     5.把Delegate类的属性window声明加上IBOutlet,这样才好在IB里面连接。(即将AppDelegate中UIWindow属性标记为IBOutlet)

        即@property (strong,nonatomic) UIWindow *window;修改为:@property (strong, nonatomic) IBOutlet UIWindow *window;

    然后,把MainWindow.xib的FileOwner的delegate设置为你的AppDelegate。FileOwner的delegate和AppDelegate(Object)连接:(蓝色连线哦)


       把Window和你AppDelegate中的Outlet关联起来:

上图即AppDelegate的outlets和Window连接起来。
     6.(可以看到,已经有一个Window对象,此window对象就是iphone的屏幕。)把window属性连接到IB中默认出现的Window。
     7.给刚才的代理再加个@property (strong,nonatomic)IBOutletUITabBarController* rootController;属性。
     8.在IB中拖个TabBarController出来,并连接到前面的Object的rootController。
     9.在代理的didFinishLaunchingWithOptions函数中修改下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{// Override point for customization after application launch.// self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    [self.windowaddSubview:rootController.view];    [self.windowmakeKeyAndVisible];return YES;}
不需要再创建window,然后把rootcontroller的view添加到当前window下面就可以了。注释掉 -(BOOL)application:didFinishLaunchingWithOptions:这个与我们从XIB加载相冲突的方法。
 10.关键一个步骤,打开项目属性,在Summary下面的Main Interface里面选择MainWindow完事。
原创粉丝点击