plist檔案的讀取和使用

2021-09-08 21:48:44 字數 676 閱讀 3566

[[nsbundle mainbundle] pathforresource:

@"sysmessagering"oftype:

@"plist"

]// plistpath

2、可以通過filemanager獲取該目錄下的所有檔案,來檢視獲取目錄是否正確

[[nsfilemanagerdefaultmanager] contentsofdirectoryatpath:[[

nsbundlemainbundle] resourcepath] error:

nil]

3、最重要的一點,plist檔案讀取的時候都是以nsdictionary的方式讀取的,先通過nsdictionary的方式把全部內容讀取出來之後

然後再去具體對應的值。

[[nsdictionaryalloc] initwithcontentsoffile:plistpath] // 讀取的整個plist檔案的值

然後取出其中的某個值

nsarray *systemmessagering = [[[nsdictionary

alloc] initwithcontentsoffile:plistpath] objectforkey:@"systemmessagering"];

獲取該陣列的值,即可使用,更改,或者、、、然後把更改的結果寫回到plist檔案

讀取和寫入plist檔案

plist檔案是標準的xml檔案,在cocoa中可以很簡單地使用。這裡介紹一下使用方法 以下 在mac和iphone中均適用。寫入plist檔案 nsmutabledictionary dict nsmutabledictionary alloc initwithcontentsoffile sam...

plist檔案的內容的讀取

方法一 nsstring str nsbundle mainbundle pathforresource flowers oftype plist nsarray arr nsarray arraywithcontentsoffole str 建立的資料型別是陣列array用此方法 nsdictio...

plist檔案的讀取和xib載入cell

例如在工程裡倒入了plist檔案 在工程裡需要用到plist檔案裡的資訊,就需要把plist檔案讀取出來。如程式 nsarray moredataarr return moredataarr 讀取plist檔案分兩步走 載入xib分三步走 註冊cell self.tableview register...