xcode - 使用原型(prototype)单元格填充表格 View

标签 xcode tableview

我有这个场景:

enter image description here

我在“原型(prototype)单元格”中添加了一个简单的“表格 View ”和下一个+1:

enter image description here

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 是空的,如下所示:

enter image description here

最佳答案

现在,您应该检查几个地方。首先是 TableView 数据源是否已经连接到 View Controller 。检查行数数据源方法是否被调用以及是否返回预期的行数。

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

其次是检查您是否在 Storyboard中指定了单元格标识符 cursosCell

enter image description here

关于xcode - 使用原型(prototype)单元格填充表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16850253/

相关文章:

ios - 分隔符不工作

iphone - 移除导航栏和按钮上的白色渐变

xcode - 如何将一份代码连接到两个git仓库?

ios - Interface Builder 无法确定 "Main.storyboard"的类型。这可能是由于缺少 SDK

iphone - 多个同时发生的 UILocalNotification

swift - UITableViewDataSource 方法不起作用

javafx-2 - 使用 tableview (JavaFX) 绑定(bind) hashmap

ios - 带有多个内衬标签的 estimatedRowHeight 导致单元格剪裁

java - 为 TableView 单个单元格设置禁用属性

ios - 当我滑动删除时表格单元格崩溃。获取错误的访问错误