首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从json到UiTableViewControll

从json到UiTableViewControll
EN

Stack Overflow用户
提问于 2013-02-25 16:50:21
回答 1查看 59关注 0票数 0

我的计划是从with服务中获取一个json,并将结果显示在一个分组的表视图中,其中包含来自json的部分。

我的json到目前为止:

代码语言:javascript
复制
{
"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"}]
}

我可以把它取出来,然后写出来。

代码语言:javascript
复制
-(void)connectionDidFinishLoading: (NSURLConnection *)connection
{
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:nil];
    NSLog(@"array contains %@",json);

    [self.tableView reloadData];
}

但如何完成其余部分并在带有部分标题的表视图中显示:1号楼1号楼1号房1号房2号房3号楼2号房1号房

诸若此类?

EN

回答 1

Stack Overflow用户

发布于 2013-02-25 17:48:04

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

示例代码:

代码语言:javascript
复制
    - (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]]];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15063156

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档