当前位置:编程学习 > wap >>

ios uitableviewcell 点击展开收缩问题


点击一下查看更多宝贝会把cell 增大,从而显示更多


在没有上拉加载之前是很正常的,但是加载了新数据之后就再点击查看更多,会出现点一下,虽然也放大了cell,但是整体的frame 往上移动了,差不多有查看宝贝那一行的宽度,而且还是先展开之后,才移动的,收缩之后也会移动一下,但是只要刷新,还原出来本来的几个就又没事了,咋回事啊。求高手指点一下,感激不尽。上一点代码。


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

    //这是要查看是第几行,然后去数组中查找当前行是不是展开状态,如果是,收缩,如果不是就展开

        NSString * str = [NSString stringWithFormat:@"%ld",(long)indexPath.section];

        if([[[NSUserDefaults standardUserDefaults] objectForKey:str] isEqualToString:@"ok"] )
                {
                    return newHeight;
                }
                else
                {
                    return 70 * 2;
                }
}
上面这是根据是不是展开了,然后返回cell的高度

下面是点击 查看更多那一块的时候触发展开收缩事件的方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * str = [NSString stringWithFormat:@"%ld",(long)indexPath.section];
    NSLog(@"点击的第%@行",str);
  
    if(indexPath.row ==2)
    {

    //newHeight是展开的高度

       newHeight = 3* 70;
        if([[[NSUserDefaults standardUserDefaults] objectForKey:str] isEqualToString:@"ok"])
        {
            [[NSUserDefaults standardUserDefaults] setObject:@"no" forKey:str];
            
        }
        else
        {
            [[NSUserDefaults standardUserDefaults] setObject:@"ok" forKey:str];
        }
        //刷新当前被点击的行
        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}
UITableview 展开 收缩 ios --------------------编程问答-------------------- 有人帮忙吗,感激不尽啊。急 --------------------编程问答-------------------- 好吧,我解决办法就是,把每个宝贝用section表示,点击之后每个宝贝section得row+1,简单点 --------------------编程问答--------------------
引用 2 楼 cruzcui 的回复:
好吧,我解决办法就是,把每个宝贝用section表示,点击之后每个宝贝section得row+1,简单点


我已经解决了
,不过还是谢谢你啊,呵呵,就只有你一个愿意帮助我。
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,