2012年8月30日 星期四

Mac Day 4 : iphone Hello world - Xcode 4.4


iOS : Start Developing iOS Apps


1. Xcode 4.4 : Create a new Xcode project



2. New Project -> Empty Application


3. Product Name : HelloWorld
    Device : iphone
    勾選 :Use Automatic Reference Counting
                 會自動計算參考個數來決定是否回收記憶體

 
4.  專案位置,並有git的版本控管



5. 樣板程式產生了



6. 主程式 :main.m
    int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

  @autoreleasepool : 支援 Auto reference counting

int UIApplicationMain (
   int argc,
   char *argv[],
   NSString *principalClassName,
   NSString *delegateClassName
);
Parameters
argc
The count of arguments in argv; this usually is the corresponding parameter to main.
argv
A variable list of arguments; this usually is the corresponding parameter to main.
principalClassName
The name of the UIApplication class or subclass. If you specify nilUIApplication is assumed.
delegateClassName
The name of the class from which the application delegate is instantiated. If principalClassName designates a subclass of UIApplication, you may designate the subclass as the delegate; the subclass instance receives the application-delegate messages. Specify nil if you load the delegate object from your application’s main nib file.
Return Value
Even though an integer return type is specified, this function never returns. When users exits an iPhone application by pressing the Home button, the application moves to the background.
7. AppDelegate.m


(1) 點選 icon 啓動 app




(2) 按下 Home 鍵返回桌面時
applicationWillResignActive:
applicationDidEnterBackgroud:
(3) 再由桌面按 icon 返回 app
applicationWillEnterForegroud:
applicationDidBecomeActive:

在 didFinishLaunchingWithOptions 中加入

    UILabel * helloLabel = [[UILabel alloc]init];
    
    helloLabel.frame = CGRectMake(50, 50, 200, 30);

    helloLabel.text= @"Hello World";
    
    [self.window addSubview:helloLabel];


8. 執行程式


完成. 但是這並不是 Model - View - Control 架構. 明天繼續...


沒有留言:

熱門文章