Xcode學(xué)習(xí)筆記 給WindowBase程序添加View
Xcode學(xué)習(xí)筆記 給WindowBase程序添加View 是本文要介紹的內(nèi)容,圖文講解,應(yīng)該很好的去了解,不多說,我們來看內(nèi)容。
1:新建一個基于windowbase的程序。你會發(fā)現(xiàn)它只有一個MainWindow.xib,打開這個文件,拖拽一個View Controller控件到下圖的MainWindow.xib窗口。
2:右鍵單擊Classes文件夾,為項目添加新的文件。如下圖:
選擇文件類型為Cocoa Touch Class,注意勾選上Targeted for iPad以及With XIB for user interface(產(chǎn)生xib文件)
點擊確定并給類起個名字,我起的是TestViewController,回到工程會發(fā)現(xiàn)多了3個文件:TestViewController.h, TestViewController.m,TestViewController.xib
***將這個xib文件拖入到Resources文件夾里。
3:雙擊在interface builder中打開MainWindow.xib,在右側(cè)的懸浮窗口里面的最上面的3個標(biāo)簽,分別選中***個標(biāo)簽(屬性標(biāo)簽)并在nib name那一欄點擊三角圖標(biāo)在彈出的選項中選擇TestViewController,這樣就將MainWindow.xib和TestViewController.xib關(guān)聯(lián)起來了。再選擇第4個標(biāo)簽(ID標(biāo)簽)并點擊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)左鍵單擊Window Base ..之后鼠標(biāo)右鍵按住它拖拽到View Con..在彈出的窗口中選中viewController,保存之。
小結(jié):Xcode學(xué)習(xí)筆記 給WindowBase程序添加View 的內(nèi)容到這里算是大功告成了。ps:為了使得效果明顯一點,你***給TestViewController.xib文件添加一個控件什么的。***希望本文對你有所幫助!