我为tableView做了一个简单的代码来显示一些玩家数据;但是,我总是得到空桌子。
这是一个包含从站点获取的数据的表。我想显示带有玩家编号(作为部分)和玩家名称(作为行)的表格。
但是在我运行程序之后,它会出现空单元格,并且似乎没有获取尝试。
谁能告诉我我的代码有什么问题?非常感谢。
#import "playerName.h"
@interface playerName ()
@end
@implementation playerName
@synthesize players = _players;
@synthesize sectionInRtf = _sectionInRtf;
- (NSMutableDictionary *)getPlayerFormRtf
{
if (!_players) {
NSURL *url = [NSURL URLWithString:@"file_on_site"];
_players = [NSMutableDictionary dictionaryWithContentsOfURL:url];
}
return _players;
}
- (NSArray *)getSections
{
if (!_sectionInRtf) {
_sectionInRtf = [self.players allKeys];
}
return _sectionInRtf;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Players";
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.sectionInRtf.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *namesInSection = [self.players objectForKey:[self.sectionInRtf objectAtIndex:section]];
return namesInSection.count;
}
//Additional Method
- (NSString *)name:(NSIndexPath *)indexPath
{
NSArray *nameInSection2 = [self.players objectForKey:[self.sectionInRtf objectAtIndex:indexPath.section]];
return [nameInSection2 objectAtIndex:indexPath.row];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"players";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = [self name:indexPath];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
@end