2015-01-13 71 views
-2

我對此很新。我已經將所有NSDictionary存儲爲NSArray,現在我想要檢索數據。我不知道該怎麼做。請幫助我。我想獲得密鑰和數據,並基於想要顯示UITableView中的數據。我只有檢索部分正在等待處理。在iOS中從NSArray中檢索數據

下面是我的NSArray

{ 
    Code = MCP3441G; 
    "Needle Description" = "1/2 Circle Round Body MH"; 
    "Needle Dimension" = "31 MM"; 
    "No. of foils per box" = 12; 
    "Per box maximum retail price" = 7440; 
    "Per box price to retailers & hospitals" = 5474; 
    Size = "2/0"; 
    "Suture type and length" = "MONOCRYL monofilament 70 CM Violet"; 
    nid = 86; 
}, 
    { 
    Code = NW1641; 
    "Needle Description" = "1/2 Circle Round Body"; 
    "Needle Dimension" = "30 MM"; 
    "No. of foils per box" = 12; 
    "Per box maximum retail price" = 4800; 
    "Per box price to retailers & hospitals" = 3510; 
    Size = "2/0 Only"; 
    "Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM"; 
    nid = 86; 
}, 
    { 
    Code = NW1642; 
    "Needle Description" = "1/2 Circle Round Body"; 
    "Needle Dimension" = "30 MM"; 
    "No. of foils per box" = 12; 
    "Per box maximum retail price" = 4800; 
    "Per box price to retailers & hospitals" = 3510; 
    Size = "1/0"; 
    "Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM"; 
    nid = 86; 
}, 
    { 
    Code = NW1648; 
    "Needle Description" = "3/8 Circle Round Body"; 
    "Needle Dimension" = "16 MM"; 
    "No. of foils per box" = 12; 
    "Per box maximum retail price" = 3600; 
    "Per box price to retailers & hospitals" = 2687; 
    Size = "4/0"; 
    "Suture type and length" = "MONOCRYL Undyed Monofilament 70 cm"; 
    nid = 86; 
}, 
    { 
    Code = NW1663; 
    "Needle Description" = "1/2 Circle Oval Round Body J.B"; 
    "Needle Dimension" = "22 MM"; 
    "No. of foils per box" = 12; 
    "Per box maximum retail price" = 5280; 
    "Per box price to retailers & hospitals" = 3870; 
    Size = "3/0"; 
    "Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM"; 
    nid = 86; 
}, 
    { 
    Code = NW1664; 
    "Needle Description" = "1/2 Circle Oval Round Body J.B"; 
    "Needle Dimension" = "26 MM"; 
    "No. of foils per box" = 12; 
    "Per box maximum retail price" = 5880; 
    "Per box price to retailers & hospitals" = 4347; 
    Size = "3/0"; 
    "Suture type and length" = "MONOCRYL Undyed Monofilament 70 CM"; 
    nid = 86; 
}, 

回答

1

有訪問數據的一些方法。首先,我建議你看一下文檔都的NSArray(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/)和NSDictionary中(https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/

要訪問的NSArray的某個元素,你可以做這樣的事情:

NSDictionary *dict = (NSDictionary*) myArray[0]; //gets the first item of the array. 

一旦你有在字典中,有很多可能的方式來訪問密鑰和數據。如果你有鑰匙,你想有一個特定的值,你可以做這樣的事情:

NSString *desc = dict[@"Needle Description"]; //gets the value for the key Needle Description 

(注意:上述使用速記 - 你也可以做更詳細的[dict objectForKey:@"Needle Description"]

你可以還可以得到所有的鍵的陣列(在表中列出,當你在你的問題中所述),但這樣做是這樣的:

NSArray *keys = [dict allKeys]; 

然後,你可以通過這些按鍵循環,輪詢的值項按項目。

再次檢查文檔以獲取更多信息。