iOS : Start Developing iOS Apps
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
- 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. Specifynil
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
(2) 按下 Home 鍵返回桌面時
applicationWillResignActive:
applicationDidEnterBackgroud:
applicationDidEnterBackgroud:
(3) 再由桌面按 icon 返回 app
applicationWillEnterForegroud:
applicationDidBecomeActive:
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 架構. 明天繼續...