ios - 如何正确折叠我的单元格?

标签 ios objective-c uitableview

当我单击第一个单元格时,它会正常工作并正确隐藏。

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"];
       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];
    }

最佳答案

如果您尝试通过缩小单元格的高度来隐藏部分单元格内容,则需要检查单元格是否设置为剪切其边界(默认情况下设置为“否”)。

enter image description here

在 Storyboard中选择原型(prototype)单元格,然后勾选“剪辑 subview ”复选框 - 当您缩小高度时,单元格应该剪辑其内容。

关于ios - 如何正确折叠我的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31536901/

相关文章:

ios - 如何在单个表中使用两个不同的自定义 UITableViewCell 子类?

objective-c - 如何从给定的日期/时间减去 1 小时

ios - 在容器 View 中嵌入表格时控件消失

ios - 具有多个部分的 TableView 的 Swift NSUserDefault?

ios - 在 iOS 中解析 XML

ios - 为什么当尝试在 Google API 中使用 iOS 的 Place Autocomplete 时,只得到 5 个结果而不是更多?

objective-c - 如何添加或替换现有 Objective-C 类的方法?

iphone - XCode:如何以编程方式获取用户的电子邮件?

ios - visibleCells 返回 tableViewCell 中 collectionView 中的所有单元格

ios - 升级到 MT 4.0 后索引 TableViews 不显示