Posted By

devb0yax on 06/22/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adison
bobbym245


NSDictionary populating to table view


 / Published in: iPhone
 

  1. .h file:
  2.  
  3. @interface ResultsViewController : UITableViewController
  4. {
  5. NSMutableArray *m_list;
  6. NSDictionary *localDict;
  7. }
  8.  
  9. @property(nonatomic,retain) NSMutableArray *m_list;
  10.  
  11. @end
  12.  
  13. ========================
  14. .m file:
  15.  
  16.  
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19.  
  20. NSDictionary *tempDict;
  21. AdInfo *shAdInfo = [AdInfo sharedAdInfo];
  22. tempDict = shAdInfo.adInfoDict;
  23. int nCountDict = [tempDict count];
  24. NSLog(@"nCountDict: %d", nCountDict);
  25. ////////////////////////
  26. NSMutableArray *myMutableArr = [[NSMutableArray alloc] init];
  27. int ctr;
  28.  
  29. for(ctr = 1; ctr <= nCountDict; ctr++)
  30. {
  31. localDict = [tempDict objectForKey:[NSString stringWithFormat:@"%d", ctr]];
  32. [myMutableArr addObject:localDict];
  33. }
  34.  
  35. self.m_list = myMutableArr;
  36. [myMutableArr release];
  37.  
  38. NSLog(@"m_list count: %d", [m_list count]);
  39. }
  40. .....
  41.  
  42. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  43.  
  44. static NSString *CellIdentifier = @"Cell";
  45.  
  46. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  47. if (cell == nil) {
  48. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
  49. }
  50.  
  51. // Configure the cell...
  52. NSUInteger row = [indexPath row];
  53. NSDictionary *newDict = [NSDictionary dictionaryWithDictionary:[m_list objectAtIndex:row]];
  54. //NSLog(@"newDict desc: %@", [newDict description]);
  55. NSString *rowString = [newDict objectForKey:@"text"];
  56. cell.textLabel.text = rowString;
  57. [rowString release];
  58.  
  59. return cell;
  60. }

Report this snippet  

You need to login to post a comment.