如何从嵌套数组中获取NSmutablearray中的对象值。

时间:2016-09-12 05:35:31

标签: ios objective-c arrays uitableview

我正在NSDictionary中从SQLite获取数据,我正在转换为NSMutableArray。现在我需要在UITableViewCell标签中添加该数组对象值。

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 ext标签上添加了数据。

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

我在单元格标签上添加值时出现此错误:

  

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSArrayI length]:无法识别的选择器发送到实例0x7ffcab275550'。

我认为上面的细节还可以。请在我出错的地方给出一些建议。

2 个答案:

答案 0 :(得分:1)

根据indexPath从数组中提取特定字典,然后从该字典中获取值。

试试这个:

Vm

答案 1 :(得分:0)

//试试这个

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