tableview 点击cell 出现下拉菜单

.m 中 开始走起

 NSIndexPath *selectIndex;//标记cell用

- (void)viewDidLoad{

selectIndex = nil;

}

//cell高度改变

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

//选中之后的cell的高度

    if (indexPath.row == selectIndex.row && selectIndex != nil){

        return 200;

    }

    else

        return 100;

}

//加载cell里

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //判断cell是否处于选中状态,并且用不同的identifier标记重用;

    //选中的cell改变高度,同时在cell的下方添加需要的button;

    if (indexPath.row == selectIndex.row && selectIndex != nil) {//选中状态

        static NSString *identifier = @"cell1";

        ***TableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:identifier];

        if (!cell1) {// 这里就可以添加下菜单里的东西了

            cell1 = [[***TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

            UIView *blackView = [[UIView alloc]initWithFrame:CGR(0, 100, ScreenWidth, 100)];

            blackView.backgroundColor = [UIColor redColor];

            [cell1.contentView addSubview:blackView];

        }

        cell1.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell1;

    }

    else{// 非选中状态

      static NSString *identifier = @"cell";

        ***TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

        if (!cell) {

            cell = [[***TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

            cell.resumeModel = resumeArry[indexPath.row];

        }

         cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;

    }

    return nil;

}

//点击cell

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    if (!selectIndex) {

        selectIndex = indexPath;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:selectIndex] withRowAnimation:UITableViewRowAnimationAutomatic];

    }

    else{

        BOOL selectTheSameRow = indexPath.row == selectIndex.row?YES:NO; 

        //两次点击不同的cell

        if (!selectTheSameRow) {

            //收起上次点击展开的cell

            NSIndexPath *tempIndexPath = [selectIndex copy];

            selectIndex = nil;

            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:tempIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

            //展开新选的cell

            selectIndex = indexPath;

            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:selectIndex] withRowAnimation:UITableViewRowAnimationAutomatic];

        }

        else{

          //相同cell 收起cell

            selectIndex = nil;      

            [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

        }

    }

    [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];

}

 这样就可以实现效果了 里面东西自己弄

 

转载于:https://www.cnblogs.com/xiaodeng90/p/8074623.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值