Xcode 使用原型单元格填充表视图
我有这样一个场景: 我在“原型单元”中添加了一个简单的“表视图”和下一个+1: informacao.hXcode 使用原型单元格填充表视图,xcode,tableview,Xcode,Tableview,我有这样一个场景: 我在“原型单元”中添加了一个简单的“表视图”和下一个+1: informacao.h NSMutableArray *arrCursos; informacao.m - (void)viewDidLoad { [super viewDidLoad]; self.title = @"Informações"; arrCursos = [[NSMutableArray alloc] init]; [arrCursos addObject:@"
NSMutableArray *arrCursos;
informacao.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;
}
我不知道为什么我的表视图是空的,如下所示:
现在,有几个地方你应该去看看。首先是表视图数据源是否已连接到视图控制器。检查是否调用了数据源方法的行数,以及该方法是否返回预期的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"%d", arrCursos.count);
return [arrCursos count];
}
第二是检查是否已在情节提要中指定单元格标识符cursorcell
问题是缺少委托和数据源tks…但问题是缺少委托和数据源datasource@user1535906是的,数据来源就是我在回答的第一部分提到的。