我正在实现一个动态表视图。此表格视图控制器通过另一个视图控制器上的按钮触摸推入。但即使日志显示单元格行正确设置,屏幕上也不显示任何内容。可能是什么原因?我已经实现的部分的数量为1。这里是表视图控制器的代码:UITableView不显示数据
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(@"Row count :%d",self.playerNames.count + 1);
return self.playerNames.count + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PlayerName";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (indexPath.row < self.playerNames.count) {
cell.textLabel.text = [self.playerNames objectAtIndex:indexPath.row];
}
NSLog(@"Cell Text :%@",cell.textLabel.text);
return cell;
}
您是否在界面构建器中将表的数据源和委托关联到了此控制器? –
请分享将tableview添加到其父视图的代码。如果单元格加载正常,那么你的问题不在委托方法中。 – KDaker