【问题标题】:How to create a dynamic cell for a table view using nib files如何使用 nib 文件为表格视图创建动态单元格
【发布时间】:2015-02-12 08:09:14
【问题描述】:

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

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

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

这是我的笔尖:

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

【问题讨论】:

  • 您的代码看起来不错,但没有足够的信息进行故障排除。你实现了 numberOfRowsInSection 吗? cellForRowAtIndexPath 甚至被调用了吗?

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


【解决方案1】:

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

当你使用 nib 时,你必须注册你的 nib

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多