如何使用nib文件为表视图创建动态单元格

时间:2014-12-13 20:56:06

标签: ios objective-c iphone uitableview core-data

我正在学习如何使用笔尖和一般新手。

我有一个表视图和另一个视图,我在其中创建用于填充此表视图的对象。我也在使用核心数据。

我的表格视图没有填充...这是我的cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *cellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    Target *target = [self.fetchedResultController objectAtIndexPath:indexPath];

    cell.textLabel.font = [UIFont fontWithName:@"Candara-Bold" size:20];

    cell.textLabel.text = target.body;

    // Configure the cell...

    return cell;
}

这是我的笔尖:

enter image description here

很想在这里得到帮助......谢谢!

1 个答案:

答案 0 :(得分:1)

你可以使用自动布局我认为这是最简单的方法!!

使用笔尖时必须注册笔尖

示例:tableView.registerNib (UINib (nibName: StoreCell, bundle: nil), forCellReuseIdentifier: StoreCell)

并且您必须将UILabel行数设置为0

此测试项目https://www.dropbox.com/s/i5cwzok1327vv1e/tableTest.zip?dl=0 enter link description here

相关问题