设为首页 加入收藏

TOP

UITableView点击每个Cell,Cell的子内容的收放(二)
2017-10-13 10:33:04 】 浏览:1380
Tags:UITableView 点击 每个 Cell 内容
ell"];

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            cell.data = self.scoreDataArray[selectedIndex.row];

            cell.isOpen = YES;

            return cell;

        }

        else

        {//收起

            YunGangScoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YunGangScoreTableViewCell"];

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            cell.data = self.scoreDataArray[selectedIndex.row];

            cell.isOpen = NO;

            return cell;

        }

    }

    else//不是自身

    {

        YunGangScoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YunGangScoreTableViewCell"];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        cell.data = self.scoreDataArray[indexPath.row];

        cell.isOpen = NO;

        return cell;

    }

}

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

{

//将索引加到数组中

    NSArray *indexPaths = [NSArray arrayWithObject:indexPath];

    //判断选中不同row状态时候

     //我自己加上的,看好多文章没有,可能我错了,selectedIndex = indexPath;

    NSLog(@"%ld",(long)selectedIndex.row);

    if (selectedIndex != nil && indexPath.row == selectedIndex.row)

    {//将选中的和所有索引都加进数组中

       // indexPaths = [NSArray arrayWithObjects:indexPath,selectedIndex, nil];

        isOpen = !isOpen;

    }

    else if (selectedIndex != nil && indexPath.row != selectedIndex.row)

   {

       indexPaths = [NSArray arrayWithObjects:indexPath, selectedIndex,nil];

        isOpen = YES;

    }

    //记下选中的索引

    selectedIndex = indexPath;

    //刷新

    [tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];

 }

大致运用的就这些内容,自己看着调试下。。。

方法二: 我试了上面方法,发现可能出现刷新等问题,也就换了下面的

这里用section当做第一个cell,然后加载view到section上,添加手势来作为点击事件,展开的内容加载cell(第二个)

直接上代码:


1.声明属性:

    //cell收放,以及记录cell的selectedIndex

    NSMutableDictionary *_showDic;//用来判断分组展开与收缩的

    int index;

2.用section的个数来展示未点击时的tableview内容

3计算点击每个section之后展开的cell的个数

4.这里自己根据需求,以及返回的内容来计算点开后的cell应该拥有的高度

5.加载点击之后的cell内容,同时传递点击的那个section的数据信息

这里刷新数据是只刷新点开一个情况,如果点开多个,数据改变应该是下面,而在cell里面赋值则不需要了

6.根据需要计算每一个section需要的高度(我这里最后一个有需要)

7.加载每个section的内容,需要注意,这里加载的view继承

UITableViewHeaderFooterView  

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

    NSArray* objs = [[NSBundle mainBundle] loadNibNamed:@"YunGangScoreTableViewCell" ow

首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇【代码笔记】iOS-两个滚动条,上.. 下一篇【代码笔记】iOS-把<br!>换..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目