Добавьте метку в первую строку UITableViewCell при повторном использовании ячеек - PullRequest
1 голос
/ 25 августа 2011

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

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

    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];

    if (cell == nil){

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];

    }

    if ([indexPath row] == 0) {

        UILabel* Label = [[UILabel alloc] initWithFrame:CGRectMake(2,2, 62, 23)];

        [Label setText:@"Text"];

        [cell addSubview:Label]; 

        [Label release];
    }

    return cell;

}

1 Ответ

3 голосов
/ 26 августа 2011

Думаю, я понял это.Я сделал 1-й ряд не для повторного использования.

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

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

    if (cell == nil){
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellsToBeReused] autorelease]; 
    }
    if ([indexPath row] == 0) {
        UITableViewCell *first_Cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
        UILabel* Label = [[UILabel alloc] initWithFrame:CGRectMake(2,2, 62, 23)];
        [Label setText:@"Text"];
        Label.backgroundColor = [UIColor whiteColor];
        [first_Cell.contentView addSubview:Label];
        [Label release];
        return first_Cell;        
    } else  {
        return cell;        
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...