私は UITableView を使用していますが、スクロールするにつれてテーブルビューのセルが徐々に太くなっていることに気付きました。コンテンツを上書きしていて、これを止めたいのですが、どこが間違っているのかわかりません。
私のUITableViewでは、なんらかの理由でテーブルビューの内容をスクロールすると、手動で作成されたUILabelでめちゃくちゃになります。
後でカスタム セルが必要になるため、手動の UILabel が必要です。
上下にスクロールすると、ラベルがどんどん太くなっていきます。それらは常に重なり合い、下の行に影響を与えることさえあります (ビューポートに入る前であっても)。
それを続けると、セルの内容が理解できなくなります。
これは、backgroundColor が に設定されていない場合にのみ発生しclearColor
ます。
私は試みましたが、効果が[cellLabel setClearsContextBeforeDrawing:YES];
あり[self.tableView setClearsContextBeforeDrawing:YES];
ませんでした。
私が使用するcell.textLabel.text
と、問題は解決するようです。
コードと画像のサンプルは次のとおりです。
// Simple table view
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
//[self configureCell:cell atIndexPath:indexPath];
NSString *txt = @"Product";
//cell.textLabel.text = txt;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *cellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, cell.frame.size.height)];
UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 120, 35)];
[cellLabel setText:txt];
[cellLabel setFont:[UIFont boldSystemFontOfSize:12]];
[cellLabel setBackgroundColor:[UIColor clearColor]];
[cellView addSubview:cellLabel];
[cellLabel release];
[cell.contentView addSubview:cellView];
[cellView release];
return cell;
}
Image follows;
![image of uitableview][1]
[1]: http://i.stack.imgur.com/5lNy6.png
// Edit to include context
I am using a dictionary to display the contents of the UITableViewCells.
I have attempted to do the following;
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
[self configureCell:cell atIndexPath:indexPath];
} // end if
// Configure the cell...
//
// Moved to inside the cell==nil
return cell;
}
-(void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
// Get the txt from the Dictionary/Plist... *removed due verboseness*
UILabel *cellLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 120, 35)];
[cellLabel setText:txt];
[cellLabel setFont:[UIFont boldSystemFontOfSize:12]];
[cellLabel setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:cellLabel];
[cellLabel release];
}
これにより、上書きの問題は修正されますが、問題が発生します。ラベルが完全にランダムな場所に繰り返し表示されます。以下は単なる例であり、他のフィールドとラベルも繰り返されます。
下の図を参照してください。