0

I am getting data from SQLite in NSDictionary and I am converting into NSMutableArray. Now I need to add that array object value in UITableViewCell label.

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;
},
  )

I have added data on cell ext label by this line.

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

I am getting this error when I add a value on cell label:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x7ffcab275550'.

I think above details are OK. Please give some suggestion where I am going wrong.

2
  • 1
    Why do you think an array would have a property called name? Do you understand what arrays are? Commented Sep 12, 2016 at 5:36
  • sorry sir but i also tried to get vale according to index value Commented Sep 12, 2016 at 5:38

2 Answers 2

1

Extract particular dictionary from array according to indexPath and then get value out of that dictionary.

Try this:

NSDictionary *dict = array[indexPath.row]
cell.stdntName.text = [dict valueForKey:@"name"];
Sign up to request clarification or add additional context in comments.

1 Comment

thats work for me thanks. Sorry for my stupid question.
0

// try like this

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

3 Comments

The range check is a bad idea. If the array which is the data source mutated without the table view being made aware, it's a programmer bug. Best to find out ASAP, but letting a runtime exception trigger a crash.
yes its fine , but how would we know either it(that array) is datasource or not for that tableview.
If he's pulling data from it to populate a cell, it's the data source. He could theoretically have a composite data source, but that's overly-complicated, and not nearly as likely. Obviously, if this data is supplemental, in a use-it-if-it's-there kind of way, one should check if one has it. That's not the usual case, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.