From json to UiTableViewControll


From json to UiTableViewControll

我的计划是从Web服务中获取一个json,并将结果显示在带有json部分的分组表视图中。

我的json-sofar:

{
"Building 1":[{"title":"Room 1","id":"1"},{"title":"Room 2","id":"11"},{"title":"Room 3","id":"12"}],
"Building 2":[{"title":"Room 1","id":"37"},{"title":"Room 2","id":"23"}],
"Building 3":[{"title":"Room 1","id":"9"},{"title":"Room 2","id":"3"}]
}

我可以把它拿出来,然后用写出来

-(void)connectionDidFinishLoading: (NSURLConnection *)connection
{
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
    NSLog(@"array contains %@",json);
    [self.tableView reloadData];
}

但是如何完成其余部分并在带有节头的表视图中显示:1号楼1号房间2号房间房间32号楼 1室

等等?

创建一个动态原型UITableviewcell(或具有所需部分的静态单元格(,并将数据从数组加载到UITableviewCells中。我们可以使用Tableview委托方法将数据加载到uitableviewcells中。

样本代码:

    - (NSInteger)numberOfSectionsInTableView: (UITableView *)tableView
    {
        return 1;
    }
    - (NSInteger)tableView: (UITableView *)tableView numberOfRowsInSection: (NSInteger)section
    {
        //NSLog(@"inputplayerslist count=%d",[playerPositionList count]);
        return [playerPositionList count];
    }


    - (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
    {
        AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
        UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"ChooseAPlayer"];
        NSString *ImagName =[[appDelegate.userSelection objectForKey:@"sportValue"] stringByAppendingString:@"Player.png"];
        UIImageView *playerGraphicImage = (UIImageView *)[self.view viewWithTag:31];
        [playerGraphicImage setImage:[UIImage imageNamed:ImagName]];
        UILabel *lblName = (UILabel *)[cell viewWithTag:101];
        [lblName setText:[playerPositionList objectAtIndex:[indexPath row]]];
        UILabel *Teams = (UILabel *)[cell viewWithTag:103];
        [Teams setText:[playerTeamidList objectAtIndex:[indexPath row]]];
        UILabel *AwayTeams = (UILabel *)[cell viewWithTag:104];
        [AwayTeams setText:[playerOPTeamidList objectAtIndex:[indexPath row]]];
        UILabel *PlayersPrice = (UILabel *)[cell viewWithTag:105];
        [PlayersPrice setText:[playerPriceList objectAtIndex:[indexPath row]]];
}
相关文章:
  • 没有找到相关文章