2011-02-03 2 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

Чтобы добавить текстField в ячейку, сделайте свой собственный UITableViewCell как this.

Update:

- (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 –

Смежные вопросы