Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Json to Uitableview
- (
- {
- "address_line1" = "6 street";
- "zipcode" = 10950;
- },
- {
- "address_line1" = "Munch lane";
- "zipcode" = 11730;
- }
- )
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = nil;
- NSDictionary *addressDictionary = nil;
- cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil){
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
- }
- if ([indexPath row] <= [[self jsonAddressArray] count]){
- rowDictionary = [[self jsonAddressArray] objectAtIndex:[indexPath row]];
- if (rowDictionary != nil){
- cell.textLabel.text = [rowDictionary objectForKey:@"address_line1"];
- cell.detailTextLabel.text = [rowDictionary objectForKey:@"zipcode"];
- }
- }
- return cell;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return myArray.count;
- }
- // Customize the appearance of table view cells.
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
- //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- }
- NSDictionary *cellDict = [myArray objectAtIndex:indexPath.row];
- cell.textLabel.text = [cellDict objectForKey:@"address_line1"];
- cell.detailTextLabel.text = [cellDict objectForKey:@"zipcode"];
- return cell;
- }
Add Comment
Please, Sign In to add comment