2016-09-12 168 views
0

我從NSDictionary從SQLite獲取數據,並將其轉換爲NSMutableArray。現在我需要在UITableViewCell標籤中添加該數組對象的值。如何從嵌套數組的NSmutablearray中獲取對象值。

arraydata (
    { 
    UUID = 995443; 
    "group_id" = 41917; 
    name = "Maninderveer Kaur"; 
    "roll_no" = 1; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995445; 
    "group_id" = 41917; 
    name = "Manjot Kaur"; 
    "roll_no" = 2; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995447; 
    "group_id" = 41917; 
    name = "Prabhjot Sharma"; 
    "roll_no" = 3; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995449; 
    "group_id" = 41917; 
    name = "Prabhjot Singh"; 
    "roll_no" = 4; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995451; 
    "group_id" = 41917; 
    name = "Prince Parbhakar"; 
    "roll_no" = 5; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995453; 
    "group_id" = 41917; 
    name = "Puneet Kaur"; 
    "roll_no" = 6; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995455; 
    "group_id" = 41917; 
    name = "Rajveer Kaur"; 
    "roll_no" = 7; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995457; 
    "group_id" = 41917; 
    name = "Sahajpreet Kaur"; 
    "roll_no" = 8; 
    "session_token" = bHKkctTPPyULIEy6rh4UKKTO9; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 1824273; 
    "group_id" = 41933; 
    name = Ankit; 
    "roll_no" = 1104; 
    "session_token" = 9Ea6FqaIKgr9gZ5Gh6UWhVQTj; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 1824271; 
    "group_id" = 41933; 
    name = Anuj; 
    "roll_no" = 1103; 
    "session_token" = 9Ea6FqaIKgr9gZ5Gh6UWhVQTj; 
    status = present; 
    "user_guid" = 995789; 
}, 
    { 
    UUID = 995695; 
    "group_id" = 41933; 
    name = "Anureet Kaur"; 
    "roll_no" = 14; 
    "session_token" = 9Ea6FqaIKgr9gZ5Gh6UWhVQTj; 
    status = present; 
    "user_guid" = 995789; 
}, 
) 

我已經在此行上添加了有關單元外部標籤的數據。

cell.stdntName.text = [array valueForKey:@"name"]; 

當我電池標籤上添加一個值,我收到此錯誤:

終止應用程序由於未捕獲的異常「NSInvalidArgumentException」,原因是:「 - [__ NSArrayI長]:無法識別的選擇發送到實例0x7ffcab275550'。

我覺得上面的細節都可以。請給我一些建議,讓我出錯。

+1

爲什麼你認爲一個數組將有一個名爲'name'屬性?你明白數組是什麼嗎? – Avi

+0

對不起,先生,但我也試圖讓價值根據指數值 –

回答

1

根據indexPath從數組中提取特定字典,然後從該字典中獲取值。

試試這個:

NSDictionary *dict = array[indexPath.row] 
cell.stdntName.text = [dict valueForKey:@"name"]; 
+1

多數民衆贊成在我的工作感謝。對不起,我的愚蠢問題。 –

0

//嘗試這樣

if [(array count] > indexpath.row) { 
    cell.stdntName.text = [[array objectAtIndex: indePath.row] valueForKey:@"name"]; 
} 
+1

範圍檢查是一個壞主意。如果作爲數據源的數組發生突變而沒有使表視圖被意識到,這是一個程序員錯誤。最好找出儘快,但讓運行時異常觸發崩潰。 – Avi

+0

是好的,但我們怎麼知道它(該數組)是否是該數據源的數據源。 –

+0

如果他從中提取數據以填充單元格,則它是數據源。他理論上可以有一個複合數據源,但這太複雜了,而且幾乎不可能。顯然,如果這些數據是補充性的,那麼在一個使用它的方法中,應該檢查一下是否有這個數據。雖然這不是通常的情況。 – Avi

相關問題