2011-02-03 3 views
1
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //static NSString *CellIdentifier = @"Cell"; 
    NSString *CellIdentifier = [NSStringstringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];  
    } 

    if (indexPath.section==0) 
    { 
      if (indexPath.row==0) 
     { 
      UILabel *Name=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 20)]; 
      [Name setText:@"First Name "]; 
      Name.tag=kViewTag; 
      [cell.contentView addSubview:Name]; 

      //[email protected]"First Name"; 
      UITextField *textName=[[UITextField alloc]initWithFrame:CGRectMake(140, 10, 150, 30)]; 
      [email protected]"Enter First Name"; 
      textName.tag=kViewTag; 
      [textName setBorderStyle:UITextBorderStyleRoundedRect]; 
      //textName.tag=0; 
      textName.clearButtonMode = UITextFieldViewModeWhileEditing; 
      textName.keyboardType=UIKeyboardTypeDefault; 
      textName.returnKeyType=UIReturnKeyDone; 
      textName.delegate=self; 
      textName.clearsOnBeginEditing=YES; 
      [cell.contentView addSubview:textName];  
     } 
    } 
    return cell; 
} 

このコードには、いくつかのテキストフィールドもあります。uitableviewcontrollerのカスタムテキストフィールド

私の問題は、私がテキストフィールドで自分のテーブルの値をスクロールしているときに、自動的に削除することです。 誰でも私を助けることができますか?

答えて

0

セルにtextFieldを追加するには、自分のUITableViewCellをthisのようにします。

更新:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = @"YourCellId"; 
    YourCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [YourCell cellFromNib]; 
    } 

    cell.yourTextField.tag = indexPath.row; 
    cell.yourTextField.text = (NSString*)[self.textFieldValues objectAtIndex:indexPath.row]; 

    return cell; 
} 

- (void)textFieldDidEndEditing:(UITextField *)textField 
{ 
    [self.textFieldValues replaceObjectAtIndex:textField.tag withObject:textField.text]; 
} 
+0

私は新しいセルを作成せずにそれを行う傾けます? –

+0

はい、それはあなた自身のUITableViewCellを使用したほうが良いです – MathieuF

+0

私自身のuitableviecellを使用しましたが、同じ問題があります...上の行はスクロール後に値をクリーニングしています。 :x –

関連する問題