2013-04-26 69 views
2

我有一个表视图和表视图4个部分。在第一节中,我只有一行,在这个房间里面增加了一个文本框。我为这个第一个单元分配一个自定义类。对于其他所有部分和行我分配第二类。但问题是当我在第一个单元格的文本字段中输入内容时。而我checkaccessorytype检查其他细胞,我滚动表。然后文本框的文本完成,也细胞的附件改变了这是代码细胞附件变化也除去

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 4; 
} 

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 

{ 
    if (section ==0) 
    { 
     return 1; 
    } 


    if (section ==1) 
    { 
     return [filterObj.priceName count]; 
    } 


    if (section ==2) 
    { 
     return [filterObj.typeName count]; 
    } 

    if (section ==3) 
    { 
     return [othersArray count]; 
    } 



    return 0; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *kCellID = @"DefaultCell"; 
    static NSString *kCellTwoID = @"tblCell"; 
    CustomCellWithTF *cell = (CustomCellWithTF *) [tableView dequeueReusableCellWithIdentifier:kCellID]; 
    customCellTwo *cellTwo = (customCellTwo *) [tableView dequeueReusableCellWithIdentifier:kCellTwoID]; 
    if(cell == nil) 
    { 
     NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"custonCell" owner:self options:nil]; 
     cell = (CustomCellWithTF *)[nibs objectAtIndex:0]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     cell.textLabel.font = [UIFont systemFontOfSize:12]; 
     cell.accessoryType = UITableViewCellStyleDefault; 

    } 

    if(cellTwo == nil) 
    { 


     NSArray *nibsTwo = [[NSBundle mainBundle] loadNibNamed:@"customCellTwo" owner:self options:nil]; 
     cellTwo = (customCellTwo *)[nibsTwo objectAtIndex:0]; 
     cellTwo.selectionStyle = UITableViewCellSelectionStyleNone; 
     cellTwo.textLabel.font = [UIFont systemFontOfSize:12]; 
     cellTwo.accessoryType = UITableViewCellStyleDefault; 
    } 

    if (indexPath.section == 0 && indexPath.row == 0) 
    { 
     cell.textLabel.text = @"Location"; 
     location = [[UITextField alloc] initWithFrame:CGRectMake(130, 10, 150, 25)]; 
     [location setBorderStyle:UITextBorderStyleRoundedRect]; 
     location.delegate = (id)self; 
     [cell addSubview:location]; 
     return cell; 
    } 

    if (indexPath.section == 1) 
    { 

     cellTwo.textLabel.text = [filterObj.priceName objectAtIndex:indexPath.row]; 


    } 

    if (indexPath.section == 2) 
    { 
     cellTwo.textLabel.text = [filterObj.typeName objectAtIndex:indexPath.row]; 

    } 

    if (indexPath.section == 3) 
    { 
     cellTwo.textLabel.text =[othersArray objectAtIndex:indexPath.row]; 

    } 



    return cellTwo; 






} 

请你告诉我怎样才能解决这个问题

+0

你根本没有回到细胞。你只能一直返回cellTwo。代码中有很多需要改变的地方。你能提供你想要达到什么样的截图吗?结果是什么? – 2013-04-26 11:22:31

+0

我正在返回单元格,您可以看到 – zeshan 2013-04-26 11:23:26

回答

0

UPDATE:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     static NSString *kCellID = @"DefaultCell"; 
     static NSString *kCellTwoID = @"tblCell"; 
     CustomCellWithTF *cell = (CustomCellWithTF *) [tableView dequeueReusableCellWithIdentifier:kCellID]; 
     customCellTwo *cellTwo = (customCellTwo *) [tableView dequeueReusableCellWithIdentifier:kCellTwoID]; 
     if(cell == nil) 
     { 
      NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"custonCell" owner:self options:nil]; 
      cell = (CustomCellWithTF *)[nibs objectAtIndex:0]; 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
      cell.textLabel.font = [UIFont systemFontOfSize:12]; 
      cell.accessoryType = UITableViewCellStyleDefault; 
    if (indexPath.section == 0 && indexPath.row == 0) 
     { 
      cell.textLabel.text = @"Location"; 
      location = [[UITextField alloc] initWithFrame:CGRectMake(130, 10, 150, 25)]; 
      [location setBorderStyle:UITextBorderStyleRoundedRect]; 
      location.delegate = (id)self; 
      [cell addSubview:location]; 
      return cell; 
     } 
     } 

     if(cellTwo == nil) 
     { 


      NSArray *nibsTwo = [[NSBundle mainBundle] loadNibNamed:@"customCellTwo" owner:self options:nil]; 
      cellTwo = (customCellTwo *)[nibsTwo objectAtIndex:0]; 
      cellTwo.selectionStyle = UITableViewCellSelectionStyleNone; 
      cellTwo.textLabel.font = [UIFont systemFontOfSize:12]; 
      cellTwo.accessoryType = UITableViewCellStyleDefault; 
if (indexPath.section == 1) 
     { 

      cellTwo.textLabel.text = [filterObj.priceName objectAtIndex:indexPath.row]; 


     } 

     if (indexPath.section == 2) 
     { 
      cellTwo.textLabel.text = [filterObj.typeName objectAtIndex:indexPath.row]; 

     } 

     if (indexPath.section == 3) 
     { 
      cellTwo.textLabel.text =[othersArray objectAtIndex:indexPath.row]; 

     } 
     } 


     return cellTwo; 
    } 
+0

但在nib文件上,我分配了标识符DefaultCell和tblCell – zeshan 2013-04-26 11:25:08

+0

这里您设置idemtifier参见CustomCellWithTF * cell =(CustomCellWithTF *)[tableView dequeueReusableCellWithIdentifier:kCellID]; customCellTwo * cellTwo =(customCellTwo *)[tableView dequeueReusableCellWithIdentifier:kCellTwoID]; – 2013-04-26 11:26:11

+0

如果你这样做,没有重用单元格(或者说只有当你滚动到已经显示的单元格时),这是实现UITableView的非常不理想的方式,它胜过了这个目的。 – 2013-04-26 11:26:47

0

每当表中获取滚动cellForRowAtIndexPath:方法执行,因此您必须全局设置该值,然后将其设置到cellForRowAtIndexPath:方法中的文本字段中,并且您的问题将得到解决。