Guest User

Untitled

a guest
Sep 11th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. Json to Uitableview
  2. (
  3. {
  4. "address_line1" = "6 street";
  5. "zipcode" = 10950;
  6. },
  7. {
  8. "address_line1" = "Munch lane";
  9. "zipcode" = 11730;
  10. }
  11. )
  12.  
  13. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  14. static NSString *CellIdentifier = @"Cell";
  15. UITableViewCell *cell = nil;
  16. NSDictionary *addressDictionary = nil;
  17.  
  18. cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  19. if (cell == nil){
  20. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
  21. }
  22. if ([indexPath row] <= [[self jsonAddressArray] count]){
  23. rowDictionary = [[self jsonAddressArray] objectAtIndex:[indexPath row]];
  24. if (rowDictionary != nil){
  25. cell.textLabel.text = [rowDictionary objectForKey:@"address_line1"];
  26. cell.detailTextLabel.text = [rowDictionary objectForKey:@"zipcode"];
  27. }
  28. }
  29. return cell;
  30. }
  31.  
  32. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  33. {
  34. return 1;
  35. }
  36.  
  37. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  38. {
  39. return myArray.count;
  40. }
  41.  
  42. // Customize the appearance of table view cells.
  43. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  44. {
  45. static NSString *CellIdentifier = @"Cell";
  46.  
  47. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  48. if (cell == nil) {
  49. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
  50. //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  51. }
  52.  
  53. NSDictionary *cellDict = [myArray objectAtIndex:indexPath.row];
  54.  
  55. cell.textLabel.text = [cellDict objectForKey:@"address_line1"];
  56. cell.detailTextLabel.text = [cellDict objectForKey:@"zipcode"];
  57.  
  58. return cell;
  59. }
Add Comment
Please, Sign In to add comment