ios - 没有单元格重用的 UITableView 中的问题

标签 ios iphone uitableview ios7

<分区>


这个问题似乎与 help center 中定义的范围内的编程无关。 .

关闭 9 年前

我正在尝试创建一个不重复使用单元格的表格 View 。

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

static NSString *CellIdentifier = @"Cell";
cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:CellIdentifier];
cell.delegate = self;
return cell;

}

但是这不会加载我的自定义单元格。但是当我添加 dequeReusableCellWithIdentifier: 时,它工作得很好。但是我不想重复使用电池。

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    SignUpUserCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (!cell) {
        cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:CellIdentifier];
    }
    cell.keyLabel.text = [parameterDictionary objectForKey:@"secondLabel"];
    cell.textField.text = [parameterDictionary objectForKey:@"secondField"];

    // and some more elements

    cell.delegate = self;
    return cell;
}

如何使用不可重用的表格单元正确创建表格 View 。我在这里做错了什么??

最佳答案

您确定这是您实际使用的代码吗?

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

static NSString *CellIdentifier = @"Cell";
cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
                                 reuseIdentifier:CellIdentifier];
cell.delegate = self;
return cell;

   }

我问的原因是你没有定义cell 是什么,代码不应该是这样的......

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

static NSString *CellIdentifier = @"Cell";
SignUpUserCell * cell = [[SignUpUserCell alloc] initWithStyle:UITableViewCellStyleDefault
                                 reuseIdentifier:CellIdentifier];
cell.delegate = self;
return cell;

   }

关于ios - 没有单元格重用的 UITableView 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21797736/

上一篇:ios - 很简单——我无法在方法 B 中访问我在方法 A 中声明的对象

下一篇:ios - 如何/如何手动更改自定义 UIView 的框架?

相关文章:

ios - 通过一个ViewController控制多个子ViewController 'root'

ios - 如何向现有应用程序添加一个或多个插件

ios - 自定义 UITableViewCells 在表中重叠

ios - UICollectionView 委托(delegate)方法 "didSelectItemAtIndexPath"在 UITableviewCell 中使用 UICollection View 时未调用

ios - 如何将用户数据存储为字符串,并在 viewDidLoad 中加载该字符串

ios - 使用_框架!仅适用于某些 pod 或 swift pod

ios - 谷歌 ios 分析不适用于少数屏幕

iphone - Cocos2D iPhone - 对象发送自动释放次数太多?

iphone - 保持同一应用程序的 android 和 iphone 版本的最佳策略是什么

ios - 如何使用受托人实现 Cosmos 星级评定?