Xcode學習筆記之WindowBase程式添加View

來源:互聯網
上載者:User

Xcode學習筆記之WindowBase程式添加View是本文要介紹的內容,主要講解了在xcode中實現WindowBase程式添加View的案例,不多說,我們先來看詳細內容。

1、建立一個基於windowbase的程式。你會發現它只有一個MainWindow.xib,開啟這個檔案,拖拽一個View Controller控制項到的MainWindow.xib視窗。

2、按右鍵Classes檔案夾,為項目添加新的檔案。如:

選擇檔案類型為Cocoa Touch Class,注意勾選上Targeted for iPad以及With XIB for user interface產生xib檔案)

點擊確定並給類起個名字,我起的是TestViewController,回到工程會發現多了3個檔案:TestViewController.h, TestViewController.m,TestViewController.xib

最好將這個xib檔案拖入到Resources檔案夾裡。

3、雙擊在interface builder中開啟MainWindow.xib,在右側的懸浮視窗裡面的最上面的3個標籤,分別選中第一個標籤(屬性標籤)並在nib name那一欄點擊三角表徵圖在彈出的選項中選擇TestViewController,這樣就將MainWindow.xib和TestViewController.xib關聯起來了。再選擇第4個標籤(ID標籤)並點擊Class的三角表徵圖在彈出的類裡面選中TestViewController,這樣就將TestViewController.xib和TestViewController類關聯起來了。

4、在XXXAppDelegate.h中添加如下代碼,藍色字型為新增代碼

 
  1. #import <UIKit/UIKit.h> 
  2. @class TestViewController;  
  3. @interface WindowBaseTestAppDelegate : NSObject <UIApplicationDelegate> {  
  4.     UIWindow *window;  
  5.     TestViewController *viewController;  
  6. }  
  7. @property (nonatomic, retain) IBOutlet UIWindow *window;  
  8. @property (nonatomic, retain) IBOutlet TestViewController *viewController;  
  9. @end 

在XXXAppDelegate.m中添加如下代碼,

 
  1. #import "WindowBaseTestAppDelegate.h"  
  2. #import "TestViewController.h"  
  3. @implementation WindowBaseTestAppDelegate  
  4. @synthesize window;  
  5. @synthesize viewController;  
  6. #pragma mark -  
  7. #pragma mark Application lifecycle  
  8. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {      
  9.     // Override point for customization after application launch.  
  10.     [window addSubview:viewController.view];  
  11.     [self.window makeKeyAndVisible];  
  12.     return YES;  
  13. }  
  14. ...  
  15. - (void)dealloc {  
  16.    [viewController release];  
  17.     [window release];  
  18.     [super dealloc];  

5、開啟MainWindow.xib檔案,滑鼠左鍵單擊WindowBase ..之後滑鼠右鍵按住它拖拽到View Con..在彈出的視窗中選中viewController,儲存之。

到這裡算是大功告成了。ps:為了使得效果明顯一點,你最好給TestViewController.xib檔案添加一個控制項什麼的。

小結:Xcode學習筆記之WindowBase程式添加View的內容介紹完了,希望本文對你有所協助。更多相關xcode的內容,請參考編輯精選。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.