UITableView 的didSelectRowAtIndexPath和didDeselectRowAtIndexPath

原文地址::https://www.cnblogs.com/qianyindichang/p/4284061.html

 

相关文章

1、TableView didSelectRowAtIndexPath 不执行----https://www.cnblogs.com/jasonduan/p/4950788.html

2、UITableView的代理方法didSelectRowAtIndexPath与手势点击的冲突----https://www.jianshu.com/p/1f9ecc9a290a

 

今天被UITableView给坑了一道,我写了一个横向的UITableView

如图,通过这两个方法实现需求的触发事件,但是能同时选中两个index,

据说UITableView不会管视图外的indexpath,所以重点来了

自己定义一个indexpath,直接上代码

 NSIndexPath *_selectedIdxPath;

其他的都跟平常的UITableView一样的,只是初始化cell的时候需要这么做

复制代码

//这是自定义的cell,按自己的需求来
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"filiter";
   FilterChooseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell = [[FilterChooseTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setImgViewImg:[UIImage imageNamed:_filiterData[indexPath.row]]];
    cell.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2);
//这是未选中的调用的方法,初始化cell的时候,恢复原状
[cell DownVideoWitnAnimation:NO]; 
if (indexPath == _selectedIdxPath)
 { 
[cell MoveUpVideoWithAnimation:NO];
 }
 return cell; 
}

复制代码

复制代码

//选中
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FilterChooseTableViewCell *cell = (FilterChooseTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    [cell MoveUpVideoWithAnimation:YES];

       _selectedIdxPath = indexPath;

 
}

复制代码

复制代码

//未选中
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    FilterChooseTableViewCell *cell = (FilterChooseTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    [cell DownVideoWitnAnimation:YES];
}

复制代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值