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