关于cell点击展开收缩的总结
2017-06-26 09:14
211 查看
在最近的项目开发,为了更好的用户体验,项目决定使用一些cell默认展开一条,并具有点击展开和收缩的功能。经过查看资料,后来通过cell 属性实现了该功能,在开发中也遇到了一些坑,在此总结,以供参考。
@property (nonatomic, strong) NSIndexPath *selectedIndex;
首先声明一个选中的index对象,注意:这里的语义属行,在刚开始我用的assign在一些机型上实现。
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; self.selectedIndex = indexPath;
设置默认选中状态,即选中的cell的index.
if ([indexPath isEqual: _selectedIndex] && _selectedIndex != nil ) { if (_isOpen == YES) { projectCell.isOpen = self.isOpen; }else{ projectCell.isOpen = NO; } } else { projectCell.isOpen = NO; }
在
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath设置选中cell要做的事情
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSArray *indexPaths = [NSArray arrayWithObject:indexPath]; if (self.selectedIndex != nil && [indexPath isEqual: _selectedIndex]) { _isOpen = !_isOpen; }else if (self.selectedIndex != nil && ![indexPath isEqual: _selectedIndex]) { indexPaths = [NSArray arrayWithObjects:indexPath,_selectedIndex, nil]; _isOpen = YES; } //记下选中的索引 self.selectedIndex = indexPath; //刷新 [tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; }
设置cell选中时的操作,当然还用要计算行高,这些我会稍后将写个demo上传到GitHub和大家交流,在这个开发中我充分认识到我们对底层研究的重要性!!!
欢迎大家一起交流!!!
相关文章推荐
- 点击UITableView的cell展开收缩
- 用UICollectionView实现点击展开收缩的cell
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- 点击UITableView的cell展开收缩
- ExpandableListView的首次加载全部展开,并且点击Group不收缩、
- ExpandableListView的首次加载全部展开,并且点击Group不收缩
- ios知识点总结——UITableView的展开与收缩及横向Table
- jQuery 关于点击菜单项,使子条目“向上”展开效果的实现
- 关于点击UIScrollView跳转的问题,以及怎么在UITableView上展示滚动视图,九宫格,自定义Cell等
- Jquery 收缩展开效果 点击标题展开或者隐藏内容
- jQuery插件treeview点击节点名称不展开、收缩节点 分类: JavaScript 2014-06-16 20:28 540人阅读 评论(0) 收藏
- 一般左边后台点击收缩展开的效果
- ExtJs中实现tree节点,全部是单击展开和收缩效果,和收藏夹点击功能一样