1
对于UITableViewController
类的cellForRowAtIndexPath:
方法,我使用下一个代码来显示包含UITextView
的单元格。将单元格文本重新打印到UITableViewCell中
有时,当我滚动包含单元格的表格,然后滚动单元格UITextView
时,它将显示单元格文本转载(好像有两个UITextView
对象,而不是一个)放入单元格中。
我能做些什么来解决这个问题?
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.contentView.bounds = CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height);
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UITextView *textView = [[UITextView alloc] initWithFrame:cell.contentView.bounds];
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
textView.editable = NO;
textView.scrollEnabled = YES;
textView.backgroundColor = [UIColor clearColor];
textView.font = [UIFont fontWithName:@"Helvetica" size:14.0];
textView.text = self.description;
[cell.contentView addSubview:textView];
[textView release];
谢谢Ole。它效果很好。 – 2010-11-15 16:21:37