使用原型单元填充表视图

时间:2013-05-31 05:20:09

标签: xcode tableview

我有这个场景:

enter image description here

我在“原型单元格”中添加了一个简单的“表格视图”和下一个+1:

enter image description here

informacao.h

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;
}

我不知道为什么我的表视图是空的,如下所示:

enter image description here

2 个答案:

答案 0 :(得分:2)

现在,您应该检查一些地方。首先是表视图数据源是否已连接到视图控制器。检查是否调用了行数据源方法,以及是否返回了预期的行数。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"%d", arrCursos.count); 
    return [arrCursos count];
}

其次是检查是否在故事板中指定了单元格标识符cursosCell

enter image description here

答案 1 :(得分:0)

问题是缺少委托和数据源

相关问题