zoukankan      html  css  js  c++  java
  • UITableView 的didSelectRowAtIndexPath和didDeselectRowAtIndexPath

      今天被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];
    
    }
  • 相关阅读:
    Python正则匹配字母大小写不敏感在读xml中的应用
    Python中的正斜杠与反斜杠
    C# 向批处理文件输入字符
    推荐我看过的几本好书给大家(1)
    windows下mysqlpython安装出错
    PJBlog的文章转换成BlogEngine的xml格式文章
    测试Writer
    一个比较好用的DBHelper
    MSN 2009在2008下面的问题
    关于GridView中绑定TemplateField值丢失的问题
  • 原文地址:https://www.cnblogs.com/qianyindichang/p/4284061.html
Copyright © 2011-2022 走看看