我的计划是从with服务中获取一个json,并将结果显示在一个分组的表视图中,其中包含来自json的部分。
我的json到目前为止:
{
"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号楼1号房1号房2号房3号楼2号房1号房
诸若此类?
发布于 2013-02-25 17:48:04
创建动态原型UITableviewcell (或具有所需部分的静态单元),并将数据从数组加载到UITableviewCells中。我们可以使用Tableview委托方法将数据加载到uitableviewcell中。
示例代码:
- (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]]];
}https://stackoverflow.com/questions/15063156
复制相似问题