2010-02-24 72 views
0

我将一些UITextFields,UITextViews和UIImageViews作为子视图添加到UITableCell中。当我向TextFields或TextView输入一些文本并向上或向下滚动表格时,出现一些绘图问题。每秒场的文字重叠等领域是这样的:iPhone SDK - UITableCell的UITextField子视图给出绘图问题?

alt text http://i49.tinypic.com/2gsl4dh.png

我创建表单元素是这样的:

self.formFields = [[NSArray alloc] initWithObjects: 
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)], 
[[UITextView alloc] initWithFrame:CGRectMake(18.0, 8.0, 284.0, 140.0)], 
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)], 
[[UITextField alloc] initWithFrame:CGRectMake(18.0, 10.0, 284.0, 22.0)], 
[[UIImageView alloc] initWithFrame:CGRectMake(18.0, 18.0, 284.0, 284.0)],nil]; 

并添加子视图:

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

     ... 
    [cell addSubview:[self.formFields objectAtIndex:indexPath.section]]; 
    return cell; 
} 

有没有什么办法解决这一问题?

回答

3

您是否在任何地方删除子视图?如果没有,他们只是继续添加到单元格中,并且因为单元格正在被重用而出现在彼此之上。删除任何旧的子视图,然后再添加一个新的子视图或(对我而言,这更符合逻辑)为每个部分创建不同的单元格标识符和单元格,然后在创建每个单元格时创建并添加相应的子视图。