2010-02-24 73 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

您是否在任何地方刪除子視圖?如果沒有,他們只是繼續添加到單元格中,並且因爲單元格正在被重用而出現在彼此之上。刪除任何舊的子視圖,然後再添加一個新的子視圖或(對我而言,這更符合邏輯)爲每個部分創建不同的單元格標識符和單元格,然後在創建每個單元格時創建並添加相應的子視圖。