Xcode學(xué)習(xí)筆記之WindowBase程序添加View
Xcode學(xué)習(xí)筆記之WindowBase程序添加View是本文要介紹的內(nèi)容,主要講解了在xcode中實(shí)現(xiàn)WindowBase程序添加View的案例,不多說,我們先來看詳細(xì)內(nèi)容。
1、新建一個(gè)基于windowbase的程序。你會(huì)發(fā)現(xiàn)它只有一個(gè)MainWindow.xib,打開這個(gè)文件,拖拽一個(gè)View Controller控件到下圖的MainWindow.xib窗口。
2、右鍵單擊Classes文件夾,為項(xiàng)目添加新的文件。如下圖:
選擇文件類型為Cocoa Touch Class,注意勾選上Targeted for iPad以及With XIB for user interface(產(chǎn)生xib文件)
點(diǎn)擊確定并給類起個(gè)名字,我起的是TestViewController,回到工程會(huì)發(fā)現(xiàn)多了3個(gè)文件:TestViewController.h, TestViewController.m,TestViewController.xib
***將這個(gè)xib文件拖入到Resources文件夾里。
3、雙擊在interface builder中打開MainWindow.xib,在右側(cè)的懸浮窗口里面的最上面的3個(gè)標(biāo)簽,分別選中***個(gè)標(biāo)簽(屬性標(biāo)簽)并在nib name那一欄點(diǎn)擊三角圖標(biāo)在彈出的選項(xiàng)中選擇TestViewController,這樣就將MainWindow.xib和TestViewController.xib關(guān)聯(lián)起來了。再選擇第4個(gè)標(biāo)簽(ID標(biāo)簽)并點(diǎn)擊Class的三角圖標(biāo)在彈出的類里面選中TestViewController,這樣就將TestViewController.xib和TestViewController類關(guān)聯(lián)起來了。
4、在XXXAppDelegate.h中添加如下代碼,藍(lán)色字體為新增代碼
- #import <UIKit/UIKit.h>
- @class TestViewController;
- @interface WindowBaseTestAppDelegate : NSObject <UIApplicationDelegate> {
- UIWindow *window;
- TestViewController *viewController;
- }
- @property (nonatomic, retain) IBOutlet UIWindow *window;
- @property (nonatomic, retain) IBOutlet TestViewController *viewController;
- @end
在XXXAppDelegate.m中添加如下代碼,
- #import "WindowBaseTestAppDelegate.h"
- #import "TestViewController.h"
- @implementation WindowBaseTestAppDelegate
- @synthesize window;
- @synthesize viewController;
- #pragma mark -
- #pragma mark Application lifecycle
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- [window addSubview:viewController.view];
- [self.window makeKeyAndVisible];
- return YES;
- }
- ...
- - (void)dealloc {
- [viewController release];
- [window release];
- [super dealloc];
- }
5、打開MainWindow.xib文件,鼠標(biāo)左鍵單擊WindowBase ..之后鼠標(biāo)右鍵按住它拖拽到View Con..在彈出的窗口中選中viewController,保存之。
到這里算是大功告成了。ps:為了使得效果明顯一點(diǎn),你***給TestViewController.xib文件添加一個(gè)控件什么的。
小結(jié):Xcode學(xué)習(xí)筆記之WindowBase程序添加View的內(nèi)容介紹完了,希望本文對(duì)你有所幫助。更多相關(guān)xcode的內(nèi)容,請(qǐng)參考編輯推薦。