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

要增加小区内的文本框使自己的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

我不能做到这一点,而无需创建新的细胞? – 2011-02-03 11:41:49