繁体   English   中英

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

[英]How to create a dynamic cell for a table view using nib files

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

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

我的表视图没有填充...这是我的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;
}

这是我的笔尖:

在此输入图像描述

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

你可以使用autolayout我认为这是最简单的方法!

当你使用笔尖时,你必须注册你的笔尖

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

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

这个测试项目为你https://www.dropbox.com/s/i5cwzok1327vv1e/tableTest.zip?dl=0 在这里输入链接描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM