2015-07-21 147 views
0

虽然我点击第一个单元正常工作并正确隐藏。如何正确折叠我的细胞?

enter image description here

而我单击第二个单元格,后端单元已被合并,并显示不正确。
enter image description here

这段代码有什么不对,请找出这段代码有什么问题。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

{ 

    return 1; 
} 
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 2; 
} 
#pragma mark table cell creating and loading the data 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *returncell; 
    AntzclubCell *cell; 
    WaterPurifierCell *cell1; 
    if(indexPath.row==0) 
    { 
     cell=[tableView dequeueReusableCellWithIdentifier:@"Antz"]; 
     cell.img_antzClub.image=[UIImage imageNamed:@"car.png"]; 
     [email protected]"CAR"; 
     cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton; 
     cell.backgroundColor=[UIColor blackColor]; 
     return cell; 

    } 
    else if (indexPath.row==1) 
    { 

    cell1=[tableView dequeueReusableCellWithIdentifier:@"WaterPurifier"]; 
    cell1.img_waterPurifier.image=[UIImage imageNamed:@"water_purifier.png"]; 
    [email protected]"WATERPURIFIER"; 
     return cell1; 
    } 
    return returncell; 
} 
#pragma mark expanding height 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    switch (indexPath.row) { 
     case 0: 
      if(indexPath.row==selectindex) 
     { 
      return 350; 
     } 

     else 
     { 
      return 132; 
     } 

      break; 
      case 1: 
      if(indexPath.row==selectindex) 
      { 
       return 333; 
      } 
      else{ 
       return 132; 
      } 
     default: 
      break; 
    } 

    return 0; 
} 

    #pragma mark user selecting option 
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"%d %d",selectindex,indexPath.row); 
    if (indexPath.row==selectindex) { 
     NSLog(@"%d",selectindex); 
     selectindex=-1; 
     [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
     return; 
    } 
     if(selectindex !=-1) 
     { 
      NSIndexPath *prepath=[NSIndexPath indexPathForRow:selectindex inSection:0]; 
      selectindex=indexPath.row; 
      [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:prepath] withRowAnimation:UITableViewRowAnimationFade]; 
      return; 
     } 
     selectindex=indexPath.row; 
     [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 

回答

1

如果您正试图通过缩小高度隐藏单元格内容的部分,你需要检查该单元被设置成夹到它的界限(默认设置为NO)。

enter image description here

选择在故事板原型细胞,并勾选“剪辑子视图”复选框 - 则该单元应当你缩小高度夹及其内容。