惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
博客园_首页
W
WeLiveSecurity
S
Secure Thoughts
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Hugging Face - Blog
Hugging Face - Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Project Zero
Project Zero
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
U
Unit 42
N
News and Events Feed by Topic
N
News and Events Feed by Topic
Hacker News - Newest:
Hacker News - Newest: "LLM"
Forbes - Security
Forbes - Security
T
Tor Project blog
I
Intezer
B
Blog
F
Full Disclosure
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Fortinet All Blogs
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
AI
AI
Google DeepMind News
Google DeepMind News
L
LINUX DO - 最新话题
Cloudbric
Cloudbric
L
Lohrmann on Cybersecurity
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
P
Privacy International News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
PCI Perspectives
PCI Perspectives
Y
Y Combinator Blog
Spread Privacy
Spread Privacy
Simon Willison's Weblog
Simon Willison's Weblog
罗磊的独立博客
Vercel News
Vercel News
A
Arctic Wolf
The Register - Security
The Register - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
H
Heimdal Security Blog
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed

博客园 - 胖胖安

Xamarin.Android 的 Google 登入 Xamarin.iOS 的 Google 登入 Xamarin.Android 的照相機使用 Xamarin.iOS 照相機功能的使用 (1) :最簡單的做法 Xamarin.iOS 的鍵盤控制 (AutoLayout 與 新的 Keyboard 事件 ) Xamarin.Android 控制鍵盤縮放 Xamarin 環境建置–Xamarin Agent install rvm iOS : TableView MultiSelect 兩個 System.IO.FileInfo 的 Extension Method SQL Server 2008 Resize LDF IIS 7 站點下,ASP.NET 3.5 與 4.0 的並存問題 jQuery AutoComplete Parameters Tips : SQL Server 2008 "saving changes is not permitted." 的解決辦法 - 胖胖安 Section 2 : 專案結構 Section 1 : 使用 XCode 建立一個新專案 iPhone 開發前的準備工作 IIS 7 上 设定ASP.NET 时应注意事项 DBML 在Beta2與正式版間差異 - 胖胖安 - 博客园
Section 3 : 程式進入點
胖胖安 · 2009-07-17 · via 博客园 - 胖胖安

我們先來看這一個名為 main.m 的檔案

裡面的內容為

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    int retVal = UIApplicationMain(argc, argv, nil, nil);

    [pool release];

    return retVal;

}

這裡面的內容不需要修改,所以我們不須要花時間看這程式。

要注意一下,在這邊有NSAutoreleasePool這個物件,我們以後在討論到記憶體回收時,再來做說明。

對Programmer 來說,真正要看的是 [專案名稱]AppDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application 

- (void)applicationWillTerminate:(UIApplication *)application 

這兩個Method 正如名稱所示一個是程式啓動後第一個可由Programmer控制的Method

另一個是程式關閉前將會執行的程式。

先來看啓動方法內寫什麼

[window addSubview:[navigationController view]];

[window makeKeyAndVisible];

就只有令人摸不著頭緒的兩行程式碼

這個時候,可以點選 MainWindow.xib ( Interface Builder 會自動開啓 )

就可以看到在這邊已經使用 Interface Builder 選取 RootViewController 為 Window's View 

並且將這個 view 設定為 navigationController的屬性

所以透過這樣的關連連結起來。

若是想要不透過 Interface Builder 作這樣的操作
可以使用如下的寫法,其中StartViewController為自己寫的ViewController

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UINavigationController *nav = [[UINavigationController alloc

      initWithRootViewController:

            [[StartViewController alloc] initWithNibName:@"StartViewController" bundle:[NSBundle mainBundle]]

];

[window addSubview:nav.view];