UITableview значение ячейки над записью снова и снова проблема? - PullRequest
1 голос
/ 31 октября 2009

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

http://www.freeimagehosting.net/image.php?fa76ce6c3b.jpg

код

  • (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];
    cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}




CGRect rectLbl2 = CGRectMake(75 ,1, 215, 32);
CGRect rectLbl3 = CGRectMake(75 ,28, 215, 30);
addLabel2= [[UILabel alloc] initWithFrame:rectLbl2];
addLabel3= [[UILabel alloc] initWithFrame:rectLbl3];



addLabel2.text = @"senthil";
[cell addSubview:addLabel2];
[addLabel2 release]; // for memory release


addLabel3.text= @"senthil";
[cell addSubview:addLabel3];
[addLabel3 release];


return cell;

}

Ответы [ 2 ]

5 голосов
/ 31 октября 2009

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

Попробуйте что-то вроде этого:

(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];
            cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        UILabel *lab;
        CGRect rectLbl2 = CGRectMake(75 ,1, 215, 32);
        lab = [[UILabel alloc] initWithFrame:rectLbl2];
        lab.tag = 2;
        [cell addSubview:lab];
        [lab release];

        CGRect rectLbl3 = CGRectMake(75 ,28, 215, 30);
        lab = [[UILabel alloc] initWithFrame:rectLbl3];
        lab.tag = 3;
        [cell addSubview:lab];
        [lab release];
    }

    ((UILabel *)[cell viewWithTag:2]).text = @"senthil";
    ((UILabel *)[cell viewWithTag:3]).text = @"senthil";

    return cell;
}
0 голосов
/ 31 октября 2009

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

Также убедитесь, что вы используете dequeueReusableCellWithIdentifier правильно. Возможно, вы не удаляете его должным образом.

Это все, что я могу сказать, не глядя на ваш код.

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