开发者

How do I store the unique_id of something in a tableview/array without displaying it to the user

I use this code to retrieve JSON details from php call and I add question to the array. So it will fill a tableview with 7 different questions as an example.

开发者_JAVA技巧
for (NSDictionary *item in [dictionary objectForKey:@"posts"]){

NSLog(@"item %@",item);

NSString *answer = [item objectForKey:@"ANSWER_1"]; 

NSString *question = [item objectForKey:@"QUESTION"];

NSString *poll_id = [item objectForKey:@"POLL_ID"];


[arrayPolls addObject:question];

I then display the question for each row with the normal method.

My question is when it comes to when the user selects a question from the uitableview. I want to be able to retrieve the poll_id from the question & not the question I displayed to the user. I would then use the poll_id to send back to php for more database stuff. How do I get the poll_id for the selection question?

NSString *selectedQuestion = [arrayPolls objectAtIndex:indexPath.row];

//  NSString *poll_id = [arrayPolls  objectAtIndex:indexPath.row]; How do I get the poll_id for the selected question?


I would probably defer the use of the dictionary to the View by populating the Array with the dictionaries instead of strings:

for (NSDictionary *item in [dictionary objectForKey:@"posts"])
{
   [arrayPolls addObject:item];
}

Then, later in your program where your view controller populates its table view, you now have the ability to reference both the string you need for each table view cell, and its poll ID.


I assume the 'dictionary' is a temporary object ? You are copying just the question for later use, while you clearly need to copy the poll_id's too, typically at the tableviewcontroller's level.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜