Перекрывающиеся ячейки контента - PullRequest
0 голосов
/ 16 декабря 2010

недавно я обнаружил действительно раздражающую ошибку:

содержимое двух ячеек (первая ячейка в таблице и последняя ячейка в таблице) смешиваются в одной ячейке (в первой и последнейячейка таблицы).Это происходит только в том случае, если я добавляю 10 записей в свою таблицу и добавляю 11 (см. Рисунок).

У вас есть идеи, как такое поведение может происходить?

С уважением, Саша

http://i.stack.imgur.com/g9fkj.jpg

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

UITableViewCell *cell = nil;

static NSString *kCellTextField_ID = @"CellTextField_ID";
cell = [tableView dequeueReusableCellWithIdentifier:kCellTextField_ID];
if (cell == nil)
{
// a new cell needs to be created
cell = [[[UITableViewCellGradient alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellTextField_ID] autorelease];

cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor blackColor];

cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
// a cell is being recycled, remove the old edit field (if it contains one of our tagged edit fields)
UIView *viewToCheck = nil;
viewToCheck = [cell.contentView viewWithTag:1];
if (!viewToCheck) {
    [viewToCheck removeFromSuperview];
}
}

NSUInteger row = [indexPath row];

if (indexPath.section == 0) {

id objId = [[self.data objectAtIndex:row] valueForKey:kViewKey];

if ([objId isKindOfClass:[UITextField class]]) {
    UITextField *textField = [[self.data objectAtIndex:row] valueForKey:kViewKey];
    [cell.contentView addSubview:textField];
} else if ([objId isKindOfClass:[UISegmentedControl class]]) {
    UISegmentedControl *segmentedField = [[self.data objectAtIndex:row] valueForKey:kViewKey];
    [cell.contentView addSubview:segmentedField];
}
} 

if (row == 0) {
[cell setPosition:UACellBackgroundViewPositionTop];
} else if (row == ([data count] - 1)) {
[cell setPosition:UACellBackgroundViewPositionBottom];
} else {
[cell setPosition:UACellBackgroundViewPositionMiddle];
}



return cell;}

1 Ответ

0 голосов
/ 16 декабря 2010
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

UITableViewCell *cell = nil;

static NSString *kCellTextField_ID = @"CellTextField_ID";
cell = [tableView dequeueReusableCellWithIdentifier:kCellTextField_ID];
if (cell == nil)
{
    // a new cell needs to be created
    cell = [[[UITableViewCellGradient alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellTextField_ID] autorelease];

    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor blackColor];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
    // a cell is being recycled, remove the old edit field (if it contains one of our tagged edit fields)
    UIView *viewToCheck = nil;
    viewToCheck = [cell.contentView viewWithTag:1];
    if (!viewToCheck) {
        [viewToCheck removeFromSuperview];
    }
}

NSUInteger row = [indexPath row];

if (indexPath.section == 0) {

    id objId = [[self.data objectAtIndex:row] valueForKey:kViewKey];

    if ([objId isKindOfClass:[UITextField class]]) {
        UITextField *textField = [[self.data objectAtIndex:row] valueForKey:kViewKey];
        [cell.contentView addSubview:textField];
    } else if ([objId isKindOfClass:[UISegmentedControl class]]) {
        UISegmentedControl *segmentedField = [[self.data objectAtIndex:row] valueForKey:kViewKey];
        [cell.contentView addSubview:segmentedField];
    }
} 

if (row == 0) {
    [cell setPosition:UACellBackgroundViewPositionTop];
} else if (row == ([data count] - 1)) {
    [cell setPosition:UACellBackgroundViewPositionBottom];
} else {
    [cell setPosition:UACellBackgroundViewPositionMiddle];
}



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