【问题标题】:Activity indicator in all tableview cells, only shows on last one所有表格视图单元格中的活动指示器,仅显示在最后一个
【发布时间】:2011-12-05 11:33:06
【问题描述】:

我正在尝试向多个表格单元格添加一个简单的 UIActivityIndi​​catorView。活动指示器是每个单元格的相同对象。但是,由于某种原因,它只显示在表格的最后一个单元格上。

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

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.accessoryView = _activityView;

    cell.textLabel.text = [_tableItems objectAtIndex:indexPath.row];
    cell.textLabel.textColor = DARK_GRAY;
    cell.detailTextLabel.text = [_tableSubtitles objectAtIndex:indexPath.row];
    cell.detailTextLabel.textColor = DARK_GRAY;

    return cell;
}

在我看来,这段代码应该让每个单元格对象获取指向同一个活动视图的指针,因此每个单元格的附属视图应该显示相同的活动指示器。但是,除了 tableView 上的最后一个之外,任何单元格的辅助视图上都没有结果,它按预期显示活动指示器。感谢您提供有关为什么会发生这种情况的任何提示。

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    您的 _activityView 是单个对象。所以它必须绘制在屏幕上的某个地方。由于它是单个对象,因此只会绘制一次。

    当您将其分配给新单元格时,它会更新内部变量。我不确定是哪些。但是这些内部变量决定了它在屏幕上的位置。

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多