当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Non-visible UITableViewCell subviews are not drawn correctly

问题描述:

I have a UITableView that takes the whole screen, each UITableViewCell has number of UILables that exceed the width of the table, so that I change its content size to fit the whole subviews.

The problem is that the subviews which are not visible at view load are not drawn correctly when I scroll horizontally to view them, no background color and no separators, and even selection line doesn't appear on click.

This image explains all:

How I can fix this problem?

BTW: No reusable cells.

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

{

static NSString *CellIdentifier = @"Cell";

UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];//[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

float startPoint = 0;

if ([_delegate billsArray].count>indexPath.row)

{

for (int j=0; j<_rowCells.count; j++)

{

NSDictionary* cellInfo = [[NSDictionary alloc]initWithDictionary:[_rowCells objectAtIndex:j]];

float width = [[cellInfo valueForKey:@"width"]floatValue];

float height = [[cellInfo valueForKey:@"height"]floatValue];

CGRect frame = CGRectMake(startPoint, 0, width, height);

startPoint = startPoint+width+5;

UILabel* label = [[UILabel alloc]initWithFrame:frame];

label.text = [[[_delegate billsArray]objectAtIndex:indexPath.row]valueForKey:[cellInfo valueForKey:@"CellID"]];

label.textColor = [UIColor blackColor];

if ([cellInfo valueForKey:@"alignment"]!=nil)

label.textAlignment = [[cellInfo objectForKey:@"alignment"]integerValue];

else

label.textAlignment = NSTextAlignmentCenter;

label.userInteractionEnabled = NO;

[cell addSubview:label];

}

}

return cell;

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: