开发者

Activity indicator in all tableview cells, only shows on last one

开发者 https://www.devze.com 2023-04-12 12:32 出处:网络
I am trying to add a simple UIActivityIndicatorView to multiple table cells. The activity indicator is the same object for each cell. However, for some reason it is only showin开发者_Go百科g on the la

I am trying to add a simple UIActivityIndicatorView to multiple table cells. The activity indicator is the same object for each cell. However, for some reason it is only showin开发者_Go百科g on the last cell in the table.

- (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;
}

It seems to me that this code should have each cell object grabbing a pointer to the same activity view, so each cell's accessory view should display the same activity indicator. However, the result is nothing on any cell's accessory view except for the last one on the tableView, which displays the activity indicator as expected. Thanks for any tips as to why this is occurring.


Your _activityView is a single object. So it has to be drawn somewhere on the screen. Since it's a single object it will only be drawn once.

When you assign it to a new cell, it updates internal variables. I'm not sure which ones. But those internal variables are responsible for its position on the screen.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号