2011-02-04 100 views
2

我在一個分組的UITableView中有一個小表單(5個字段)。每個UITextField都在一個UITableView單元內。點擊textField時,會彈出鍵盤,然後您可以將某些單元格向外滾動,當您將它們拉下時,其內容將被刪除。UITableViewCell裏面的UITextField被滾動刪除

我正確地假設他們已被重新繪製,所以他們的內容不見了?如果是這樣,防止這種情況的最好方法是什麼?由於我只有5個字段,當滾動到視圖中時,是否必須重繪我的單元格?

我重用細胞:

static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 

    } 

回答

5

你可以有你的文本字段的一個單獨的數組並實現您創建細胞回調是這樣的:

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 

    } 
    [[cell.contentView subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)]; 

    [cell.contentView addSubview: [textFieldsArray objectsAtIndex: indexPath.row]]; 

    return cell; 

} 
相關問題