UITableView добавить элемент управления проблема в iphone - PullRequest
0 голосов
/ 15 июля 2010

Я добавляю индикатор активности в каждую строку таблицы.Проблема в том, что каждый раз, когда я прокручиваю, он снова добавляется в ячейку, перезаписывая предыдущую.Пожалуйста, дайте мне знать, какой лучший способ добавить элемент управления в ячейку табличного представления.

UIActivityIndicatorView *a;

// Настройка внешнего вида ячеек табличного представления.

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    a = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [a startAnimating];
    [cell.contentView addSubview:a];

    // Configure the cell.

    return cell;
}

1 Ответ

0 голосов
/ 15 июля 2010

Добавляйте индикатор в ячейку только при его создании, тогда вы можете получить к нему доступ, используя свойство тега:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    a = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    a.tag = 10;
    [cell.contentView addSubview:a];
}
UIActivityIndicatorView* aView = [cell.contentView viewWithTag:10];
[aView startAnimating];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...