2015-07-21 47 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

選擇在故事板原型細胞,並勾選「剪輯子視圖」複選框 - 則該單元應當你縮小高度夾及其內容。