iOS學習筆記3 NSBundle的使用

2021-06-19 20:58:38 字數 973 閱讀 1151

bundle是乙個目錄,其中包含了程式會使用到的資源. 這些資源包含了如影象,聲音,編譯好的**,nib檔案(使用者也會把bundle稱為plug-in). 對應bundle,cocoa提供了類nsbundle.

nsbundle束,是一種特定的檔案型別,其中的內容遵循特定的結構。

nsbundle的乙個主要作用是獲取resources資料夾中的資源

訪問其他目錄資源的方法:

nsbundle * 

gbundle

gbundle= [nsbundle bundlewithpath

nsstring *path = [gbundle pathforimageresource:@"mom"];

nsimage *momphoto = [[nsimage alloc] initwithcontentsoffile:path];

bundle中可以包含乙個庫. 如果我們從庫得到乙個class, bundle會連線庫,並查詢該類:

class newclass = [gbundle classnamed:@"rover"];

id newinstance = [[newclass alloc] init];

如果不知到class名,也可以通過查詢主要類來取得

class aclass = [goodbundle principalclass];

id aninstance = [[aclass alloc] init];

可以看到, nsbundle有很多的用途.在這當中, nsbundle負責(在後台)載入nib檔案. 我們也可以不通過nswindowcontroller來載入nib檔案, 直接使用nsbundle:

bool successful = [nsbundle loadnibnamed:@"about" owner:someobject];

注意:我們指定了乙個物件someobject作為nib的file's owner

IOS學習筆記 (3)

使用控制器和檢視 model 應用程式的核心 負責計算與建立乙個虛擬世界,它不依靠view與controller就能存在。乙個沒有外觀介面的應用程式 controller在xcode通常是指view controller。可以把它想成一座model跟view之間的橋梁。view則是乙個讓使用者可以與...

iOS學習筆記3 獲取裝置資訊

1.xcode中如何修改product name?選擇專案 targets build settings 搜尋product name 即可 2.ios 如何獲取螢幕大小 3.ios 裝置的螢幕尺寸 解析度及其螢幕邊長比例詳細情況是怎樣的 4.ios 如何獲取系統版本 5.獲得ios系統版本號的函式...

IOS學習筆記

uiview beginanimations view flip context nil 設定動畫塊 uiview setanimationduration 1.25 動畫時間 uiview setanimationcurve uiviewanimationcurveeaseinout 動畫曲線 u...