我有这个场景:
我在“原型(prototype)单元格”中添加了一个简单的“表格 View ”和下一个+1:
infomacao.h
NSMutableArray *arrCursos;
infomacao.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Informações";
arrCursos = [[NSMutableArray alloc] init];
[arrCursos addObject:@"[G] - Odontologia"];
[arrCursos addObject:@"[P/LT] - Odontologia"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arrCursos count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cursosCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [arrCursos objectAtIndex:indexPath.row];
return cell;
}
我不知道为什么我的表格 View 是空的,如下所示:
最佳答案
现在,您应该检查几个地方。首先是 TableView 数据源是否已经连接到 View Controller 。检查行数数据源方法是否被调用以及是否返回预期的行数。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%d", arrCursos.count);
return [arrCursos count];
}
其次是检查您是否在 Storyboard中指定了单元格标识符 cursosCell
。
关于xcode - 使用原型(prototype)单元格填充表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16850253/