目 錄
XI
目 錄
第Ⅰ部分 入 門
第1章 iOS 4編程快速入門 ························3
1.1 獲取iPhone SDK ································ 3
1.2 iPhone SDK的組件 ···························· 5
1.2.1 Xcode ········································· 5
1.2.2 iPhone Simulator ······················· 7
1.2.3 Interface Builder ······················ 10
1.2.4 Instruments ······························ 11
1.3 iPhone OS架構概述 ························· 11
1.4 起步前需要瞭解的一些信息 ·········· 13
1.4.1 iPhone OS的版本 ···················· 13
1.4.2 在真實設備上進行測試 ········ 14
1.4.3 屏幕分辨率 ····························· 14
1.5 小結 ·················································· 15
第2章 編寫第一個“Hello World!”
應用程序 ·········································16
2.1 Xcode快速起步 ······························· 16
2.1.1 使用Interface Builder ·············· 18
2.1.2 編寫代碼 ································· 22
2.2 定製應用程序圖標 ·························· 23
2.3 顯示啓動畫麵 ·································· 25
2.4 小結 ·················································· 27
第3章 視圖、插座變量與動作 ················28
3.1 插座變量和動作 ······························ 28
3.2 使用視圖 ·········································· 34
3.2.1 使用警告視圖 ························· 35
3.2.2 使用動作錶單 ························· 37
3.2.3 頁麵控件與圖像視圖 ············· 39
3.2.4 使用Web視圖 ························· 46
3.3 使用代碼動態添加視圖 ·················· 48
3.4 理解視圖層次結構 ·························· 51
3.5 小結 ·················································· 52
第4章 視圖控製器 ·····································54
4.1 View-based Application模闆 ··········· 54
4.2 Window-based Application模闆 ······ 64
4.2.1 以編程的方式添加視圖
控製器和視圖 ························· 69
4.2.2 創建並連接動作 ····················· 72
4.2.3 切換視圖窗口 ························· 75
4.2.4 為視圖窗口切換添加動畫 ······ 77
4.3 Split View-based Application模闆 ······ 79
4.4 Tab Bar Application模闆 ················· 96
4.5 小結 ················································ 101
第5章 iPhone和iPad的多平颱支持 ······· 103
5.1 方法1:修改設備目標設置··········· 103
5.2 方法2:創建Universal應用程序 ··· 110
5.3 方法3:維護兩個代碼庫 ··············· 116
5.4 選擇方法 ········································ 118
5.5 小結 ················································ 119
第6章 鍵盤輸入 ······································ 120
6.1 使用鍵盤 ········································ 120
6.2 定製輸入類型 ································ 121
6.2.1 隱藏鍵盤 ······························· 122
6.2.2 當視圖加載完畢後自動
顯示鍵盤 ······························· 127
6.3 檢測鍵盤是否可見 ························ 127
6.3.1 使用Scroll View ···················· 128
6.3.2 顯示鍵盤時滾動視圖 ··········· 131
6.4 小結 ················································ 136
第7章 屏幕鏇轉 ······································ 138
7.1 響應設備鏇轉 ································ 138
7.1.1 不同類型的屏幕方嚮 ··········· 140
7.1.2 處理鏇轉 ······························· 141
iOS 4編程入門經典
XII
7.2 以編程的方式鏇轉屏幕 ················ 145
7.2.1 在運行期間鏇轉屏幕 ··········· 145
7.2.2 當加載時在指定的方嚮
上顯示Vi ew窗口 ··············· 146
7.3 小結 ················································ 146
第Ⅱ部分 顯示和持久化數據
第8章 使用錶視圖 ·································· 151
8.1 簡單的錶視圖 ································ 151
8.1.1 添加Header與Footer ············· 156
8.1.2 添加圖像 ······························· 157
8.1.3 顯示所選項 ··························· 158
8.1.4 縮進 ······································· 160
8.1.5 修改行高 ······························· 161
8.2 在Navigation-based Application中
使用錶視圖 ···································· 162
8.3 分節顯示 ········································ 162
8.3.1 添加索引 ······························· 169
8.3.2 添加搜索功能 ······················· 169
8.3.3 詳情顯示與選取標記 ··········· 180
8.3.4 導航到另外一個View窗口 ······ 181
8.4 小結 ················································ 187
第9章 應用程序首選項 ························· 188
9.1 創建應用程序首選項 ···················· 188
9.2 以編程的方式訪問設置值 ············ 194
9.2.1 加載設置值 ··························· 198
9.2.2 重置首選項設置值 ··············· 200
9.2.3 保存設置值 ··························· 201
9.3 小結 ················································ 202
第10章 文件處理 ··································· 204
10.1 理解應用程序文件夾 ················· 204
10.1.1 使用Documents與Library
文件夾 ······························· 205
10.1.2 將文件存儲到臨時
文件夾中 ··························· 209
10.2 使用屬性列錶 ····························· 209
10.3 復製打包的資源 ························· 216
10.4 小結 ············································· 217
第11章 使用SQLite3進行數據庫
存儲 ············································ 219
11.1 使用SQLite3 ································ 219
11.2 創建並打開數據庫 ····················· 221
11.2.1 檢查創建的數據庫 ··········· 223
11.2.2 創建錶 ······························· 223
11.2.3 插入記錄 ··························· 224
11.2.4 綁定變量 ··························· 226
11.2.5 檢索記錄 ··························· 228
11.3 在應用程序中打包SQLite
數據庫 ········································· 230
11.4 小結 ············································· 232
第Ⅲ部分 iOS 4高級編程技術
第12章 簡單動畫和視頻播放 ·············· 235
12.1 使用NSTimer類 ·························· 235
12.2 變換視圖 ····································· 241
12.2.1 平移 ··································· 242
12.2.2 鏇轉 ··································· 244
12.2.3 縮放 ··································· 246
12.3 為一係列圖像增加動畫效果 ······ 246
12.4 在iPhone中播放視頻 ·················· 248
12.5 小結 ············································· 251
第13章 訪問內置應用程序 ··················· 253
13.1 發送e-mail ··································· 253
13.1.1 調用Safari ························· 258
13.1.2 調用撥號程序 ··················· 259
13.1.3 調用SMS ··························· 259
13.2 訪問照相機與照片庫 ················· 261
13.2.1 訪問照片庫 ······················· 261
13.2.2 訪問照相機 ······················· 270
13.3 小結 ············································· 273
第14章 手勢識彆 ··································· 275
14.1 識彆手勢 ····································· 275
14.1.1 輕拍 ··································· 276
14.1.2 捏拉 ··································· 280
14.1.3 鏇轉 ··································· 282
14.1.4 搖動或拖曳 ······················· 285
目 錄
XIII
14.1.5 滑動 ··································· 287
14.1.6 長按 ··································· 292
14.2 檢測觸摸 ····································· 295
14.2.1 檢測單點觸摸 ··················· 296
14.2.2 檢測多點觸摸 ··················· 300
14.2.3 實現捏拉手勢 ··················· 302
14.2.4 實現拖曳手勢 ··················· 308
14.3 小結 ············································· 310
第15章 訪問加速計 ······························· 312
15.1 使用加速計 ································· 312
15.2 可視化加速計數據 ····················· 315
15.3 使用Shake API檢測搖動 ············ 318
15.4 小結 ············································· 324
第Ⅳ部分 網絡編程技術
第16章 Web 服務 ·································· 327
16.1 使用XML Web服務的基礎
知識 ············································· 327
16.1.1 使用SOAP 1.1 ·················· 329
16.1.2 使用SOAP 1.2 ·················· 330
16.2 在iPhone應用程序中使用Web
服務 ············································· 331
16.3 解析XML響應 ···························· 337
16.4 小結 ············································· 341
第17章 藍牙編程 ··································· 343
17.1 使用Game Kit框架 ······················ 343
17.1.1 搜索對等設備 ··················· 343
17.1.2 發送和接收數據 ··············· 350
17.2 實現語音聊天 ····························· 352
17.3 小結 ············································· 359
第18章 Bonjour編程 ····························· 361
18.1 創建應用程序 ····························· 361
18.2 發布服務 ····································· 362
18.3 搜索服務 ····································· 365
18.4 小結 ············································· 371
第19章 Apple推送通知服務 ················ 373
19.1 生成證書請求 ····························· 374
19.2 生成開發證書 ····························· 375
19.3 創建應用程序ID ························· 378
19.3.1 針對推送通知
配置App ID······················· 380
19.3.2 創建Provisioning Profile ··· 382
19.3.3 在設備上安裝
Provisioning Profile ·········· 384
19.4 創建iPhone應用程序 ·················· 384
19.5 創建推送通知提供者 ················· 388
19.6 小結 ············································· 391
第20章 顯示地圖 ··································· 392
20.1 使用Map Kit框架顯示地圖和
監視變化 ····································· 392
20.2 獲得位置數據 ····························· 397
20.2.1 使用地圖顯示位置 ··········· 402
20.2.2 獲取方嚮信息 ··················· 405
20.2.3 鏇轉地圖 ··························· 409
20.2.4 顯示注記 ··························· 414
20.2.5 逆地理編碼 ······················· 418
20.2.6 顯示箭頭按鈕 ··················· 422
20.3 小結 ············································· 424
第21章 後颱應用程序 ··························· 426
21.1 理解iPhone中的後颱執行 ·········· 426
21.1.1 檢查不同的應用程序
狀態 ··································· 427
21.1.2 禁用後颱模式 ··················· 429
21.1.3 檢測多任務支持 ··············· 431
21.1.4 在後颱跟蹤位置 ··············· 431
21.1.5 使位置應用程序更加
節能 ··································· 435
21.2 本地通知 ····································· 437
21.3 小結 ············································· 443
第Ⅴ部分 附 錄
附錄A 在實際設備上進行測試 ············ 447
A.1 注冊iPhone開發人員計劃 ··········· 447
A.2 獲得設備的UDID ························ 447
iOS 4編程入門經典
XIV
A.3 登錄到iPhone Provisioning
Portal ············································· 448
A.4 生成證書 ······································ 449
A.5 注冊設備 ······································ 452
A.6 創建應用程序ID ·························· 454
A.7 創建Provisioning Profile ·············· 455
A.8 理解應用程序ID和通配符 ·········· 458
A.9 準備提交到App Store ·················· 461
A.10 小結 ············································ 466
附錄B Xcode快速入門 ························· 467
B.1 啓動XCODE ································· 467
B.1.1 Xcode支持的項目類型 ······· 467
B.1.2 定製工具欄 ························ 470
B.1.3 代碼感知 ···························· 470
B.1.4 運行應用程序 ···················· 471
B.2 調試應用程序 ······························· 471
B.2.1 錯誤 ···································· 472
B.2.2 警告 ···································· 472
B.2.3 設置斷點 ···························· 473
B.2.4 使用NSLog()方法 ·············· 475
B.2.5 文檔 ···································· 475
附錄C Interface Builder快速入門 ······ 476
C.1 .XIB窗口 ······································· 476
C.2 設計視圖 ······································· 477
C.3 Inspector窗口 ································ 478
C.3.1 Attributes Inspector窗口 ··· 478
C.3.2 Connections Inspector
窗口 ····································· 479
C.3.3 Size Inspector窗口 ············· 479
C.3.4 Identity Inspector窗口 ········ 479
C.4 Library窗口 ··································· 479
C.5 插座變量與動作 ··························· 480
C.5.1 創建插座變量與動作 ········ 480
C.5.2 連接-插座變量與動作 ······ 483
附錄D Objective-C快速教程 ··············· 487
D.1 指令 ·············································· 487
D.2 類 ·················································· 488
D.2.1 @interface ·························· 488
D.2.2 @implementation ··············· 488
D.2.3 @class ································ 489
D.2.4 類的實例化 ························ 490
D.2.5 字段 ···································· 491
D.2.6 訪問權限 ···························· 491
D.2.7 方法 ···································· 492
D.2.8 消息發送(調用方法) ········· 494
D.2.9 屬性 ···································· 495
D.2.10 初始化器 ·························· 498
D.3 內存管理 ······································ 500
D.4 協議 ·············································· 506
D.5 選擇器 ·········································· 508
D.6 類彆 ·············································· 509
· · · · · · (
收起)