2013-01-08 42 views
1

我有一個由plist填充的tableView。訪問由plist填充的tableView的下一個項目

plist中的每個項目都有自己的ID。

plist中的結構是這樣的:

Root  
>Item 0 
    Title (Title of the first section in the tableView) 
    Rows (Array -> Rows of the first section) 
    >Item 0 
     id 
     name 
     description 
     image 
    >Item 1 
     id 
     name 
     description 
     image 
     //etc 

由於該圖像的會談超過1000個字更好,那就是:

http://i49.tinypic.com/2ql5xtz.png

現在,我想訪問該從detailView的plist的下一個項目,但我不知道該怎麼做或機制應該是什麼樣子。 我搜索了很多東西來完成這個任務,但是我沒有找到任何可以幫助我的東西,這就是我在這裏問的原因。

我已經在detailView中打開了plist(從訪問id的tableView打開),我想創建一個按鈕或其他東西去下一個項目。

例如,如果detailView是Item 0的id,我需要訪問下一個id,它是Item 1 id。

有沒有人做過這個?

非常感謝您提前。

+0

你能展示一些你用來訪問plist並顯示它的代碼嗎? –

回答

2

這很簡單,在DetailView中加載你的plist,然後做其餘的事情。

+0

該項目看起來不錯!非常感謝!我會盡力回覆你 – Phillip

+0

完美的工作!非常感謝,你救了我的命! – Phillip

1

開始通過導入的plist(這適用於當它被存儲在包):

NSError *error = nil; 
NSString *file = [[NSBundle mainBundle] pathForResource:@"Name" ofType:@"plist"]; 
if (!file) { 
     // Handle error if file not found 
} 

然後打開該文件作爲字典(我假設你鴕鳥政策需要的初始排列):

// Open the file 
NSArray *array = [NSArray arrayWithContentsOfFile:file]; 
NSDictionary *dictionary = [array objectAtIndex:0]; // Skipped checking if array is empty 
if (!dictionary) { 
     NSLog(@"Failed to process plist file"); // Handle error 
} 

然後你就可以查詢字典所需要的對象,即與關鍵@「的myKey」數組在這種情況下:

NSArray *rowArray= [dictionary objectForKey:@"MyKey"]; 

然後,您可以從數組中檢索下一個對象。

+0

@Pheel - 如果您有結論,請接受答案。 –