UITableViewCell снова и снова выделяется при прокрутке - PullRequest
1 голос
/ 06 июля 2011

Если UITableViewCell был выделен во время прокрутки, он не должен быть перераспределен.Это однако.Как я могу предотвратить это?

1 Ответ

0 голосов
/ 06 июля 2011

Если вы хотите использовать ячейку повторно, напишите в cellForRowAtIndexPath что-то вроде этого

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


    if (cell == nil) 
    {
     CGRect CellFrame;

        CGRect nameLabelFrame; 

        CGRect countLabelFrame;

        CellFrame = CGRectMake(0, 0, 320, 80);

        nameLabelFrame = CGRectMake(10, 10, 270, 50);
        countLabelFrame = CGRectMake(10, 58, 270, 12);


        cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:CellIdentifier] autorelease];
        UILabel *lblTemp;
        //UIImageView *imgTemp;

        lblTemp = [[UILabel alloc] initWithFrame:nameLabelFrame];
        lblTemp.tag = 1;
        [cell.contentView addSubview:lblTemp];
        [lblTemp release];



        lblTemp = [[UILabel alloc] initWithFrame:countLabelFrame];
        lblTemp.tag = 3;
        [cell.contentView addSubview:lblTemp];
        [lblTemp release];

}

//And outside of if condition access these labels by this

    //UIConstruction
        UILabel *nameLabel = (UILabel *)[cell viewWithTag:1];

        UILabel *countLabel = (UILabel *)[cell viewWithTag:3];

и используйте эти метки или элементы управления, что вам нужно, если это условие

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...