当我单击第一个单元格时,它会正常工作并正确隐藏。
当我点击第二个单元格时,后端单元格已被合并并且显示不正确。
这段代码有什么问题请找出这段代码有什么问题。
-(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"];
cell.lbl_antzClub.text=@"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"];
cell1.lbl_waterPurifier.text=@"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];
}
最佳答案
如果您尝试通过缩小单元格的高度来隐藏部分单元格内容,则需要检查单元格是否设置为剪切其边界(默认情况下设置为“否”)。
在 Storyboard中选择原型(prototype)单元格,然后勾选“剪辑 subview ”复选框 - 当您缩小高度时,单元格应该剪辑其内容。
关于ios - 如何正确折叠我的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31536901/