uitableview 展开 cell 位置的问题

huobaovs 2015-05-20 11:48:15
请教一下 ,我定义了一个tableview 当点击cell时, 展开cell(1400,超过屏幕的高了),现在每次展开后 cell的位置都在屏幕上方, 如何让cell保持不动, 让cell自动向下展开?
...全文
184 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
huobaovs 2015-05-22
  • 打赏
  • 举报
回复
我是用的网上的一个开源的封好的tableview类 :HVTableView 他有一个代理函数 //perform your expand stuff (may include animation) for cell here. It will be called when the user touches a cell -(void)tableView:(UITableView *)tableView expandCell:(UITableViewCell *)cell withIndexPath:(NSIndexPath *)indexPath { // 此处我没有做任何操作 而是在另外一个函数执行的cell展开操作 } // 这里动态返回高度 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath isExpanded:(BOOL)isexpanded { if (isexpanded) return 1400; return SCREEN_HEIGHT/10; } //下面这个函数是我执行展开cell的地方 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath isExpanded:(BOOL)isExpanded { static NSString *CellIdentifier = @"aCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; cell.selectionStyle = UITableViewCellSelectionStyleNone; // cell的加载 blablabla 太长不贴了哈 } if (!isExpanded) //prepare the cell as if it was collapsed! (without any animation!) { [cell.contentView viewWithTag:7].transform = CGAffineTransformMakeRotation(0); } else ///prepare the cell as if it was expanded! (without any animation!) { //这里展开cell 加载展开后的视图什么的 } return cell; } 这样写是不是有问题?
huobaovs 2015-05-22
  • 打赏
  • 举报
回复
求大神指教
Bannings 2015-05-21
  • 打赏
  • 举报
回复
引用 4 楼 huobaovs 的回复:
[quote=引用 3 楼 zhangao0086 的回复:] [quote=引用 2 楼 huobaovs 的回复:] [quote=引用 1 楼 zhangao0086 的回复:] 展开的 Cell 的代码怎么实现的?是直接更新这个 Cell 的高度还是插入了一个新的 Cell?
我是直接更新这个cell的高度, 每次点击展开, 这个cell都会往上移,好像默认就显示到展开后的cell的中间位置。。。不知道这样表达能否理解。。。[/quote] Cell 默认就是向下展开的,我写了一个很简单的 Demo:

static NSIndexPath *selectedIndexPath = nil;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath == selectedIndexPath) {
        return 1400;
    } else {
        return 60;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    selectedIndexPath = indexPath;
    
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
[/quote] 为什么我写的展开后就直接向两边展开了 [/quote] 上代码,方便的话把工程打包传上来
huobaovs 2015-05-21
  • 打赏
  • 举报
回复
引用 3 楼 zhangao0086 的回复:
[quote=引用 2 楼 huobaovs 的回复:] [quote=引用 1 楼 zhangao0086 的回复:] 展开的 Cell 的代码怎么实现的?是直接更新这个 Cell 的高度还是插入了一个新的 Cell?
我是直接更新这个cell的高度, 每次点击展开, 这个cell都会往上移,好像默认就显示到展开后的cell的中间位置。。。不知道这样表达能否理解。。。[/quote] Cell 默认就是向下展开的,我写了一个很简单的 Demo:

static NSIndexPath *selectedIndexPath = nil;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath == selectedIndexPath) {
        return 1400;
    } else {
        return 60;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    selectedIndexPath = indexPath;
    
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
[/quote] 为什么我写的展开后就直接向两边展开了
Bannings 2015-05-21
  • 打赏
  • 举报
回复
引用 2 楼 huobaovs 的回复:
[quote=引用 1 楼 zhangao0086 的回复:] 展开的 Cell 的代码怎么实现的?是直接更新这个 Cell 的高度还是插入了一个新的 Cell?
我是直接更新这个cell的高度, 每次点击展开, 这个cell都会往上移,好像默认就显示到展开后的cell的中间位置。。。不知道这样表达能否理解。。。[/quote] Cell 默认就是向下展开的,我写了一个很简单的 Demo:

static NSIndexPath *selectedIndexPath = nil;
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath == selectedIndexPath) {
        return 1400;
    } else {
        return 60;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    selectedIndexPath = indexPath;
    
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
huobaovs 2015-05-21
  • 打赏
  • 举报
回复
引用 1 楼 zhangao0086 的回复:
展开的 Cell 的代码怎么实现的?是直接更新这个 Cell 的高度还是插入了一个新的 Cell?
我是直接更新这个cell的高度, 每次点击展开, 这个cell都会往上移,好像默认就显示到展开后的cell的中间位置。。。不知道这样表达能否理解。。。
Bannings 2015-05-20
  • 打赏
  • 举报
回复
展开的 Cell 的代码怎么实现的?是直接更新这个 Cell 的高度还是插入了一个新的 Cell?

29,049

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧