UITableView使用小结(滚动到顶部、获取cell、cell选中状态、刷新cell或者section)
2016-01-08 14:34
996 查看
1.让tableview
滚动到顶部 一句话搞定
2.获取tableView的cell
3.设置全部cell选中状态
4.UITableview 刷新某一个cell 或 section
5.改变Tableview的cell的选中背景颜色
6.TableviewCell默认选中某一行
滚动到顶部 一句话搞定
[_tableViewsetContentOffset:CGPointMake(0,0)animated:NO];
2.获取tableView的cell
- (UITableViewCell *)cellAtIndexRow:(NSInteger)row andAtSection:(NSInteger) section { UITableViewCell * cell = (UITableViewCell *)[_tableViewcellForRowAtIndexPath:[NSIndexPathindexPathForRow:row inSection:section]]; return cell; }
3.设置全部cell选中状态
- (void)buttonClick:(UIButton *)button { //设置全部cell选中状态 for(NSIndexPath *cellindexin [_tableViewindexPathsForVisibleRows]) { //根据indexpath获取cell UITableViewCell *cell = [_tableViewcellForRowAtIndexPath:cellindex]; if(_isAllSelect) { cell.selected = YES; } else { cell.selected = NO; } } }
4.UITableview 刷新某一个cell 或 section
- (void)refreshSectionOrCell { //一个section刷新 NSIndexSet *indexSet=[[NSIndexSetalloc]initWithIndex:2]; [_tableViewreloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic]; //一个cell刷新 NSIndexPath *indexPath=[NSIndexPathindexPathForRow:3inSection:0]; [_tableViewreloadRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]withRowAnimation:UITableViewRowAnimationNone]; }
5.改变Tableview的cell的选中背景颜色
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame]; cell.selectedBackgroundView.backgroundColor = [UIColor redColor];
6.TableviewCell默认选中某一行
// 默认选中第一行 [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone]; // 实现了选中第一行的方法 [self tableView:_mainIndustryTableView didSelectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; //例如: // 默认下选中状态 - (void)customAtIndex:(UITableView *)tableView { // 默认选中第一行 [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone]; if ([tableView isEqual:_mainIndustryTableView]) { [self tableView:tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; } }
相关文章推荐
- UVa 12100 - Printer Queue【队列和优先队列】
- Android 更新UI的两种方法——handler和runOnUiThread()
- Android Build类
- 【LeetCode】Repeated DNA Sequences 解题报告
- Request与Response常用方法总结
- Android Contacts (一)ContentResolver query 参数详解
- UIPickerView组件的使用之——省市联动
- Map对value进行排序
- org.hibernate.exception.JDBCConnectionException: could not execute query
- apktool,dex2jar,jd-gui简单使用与实战
- 如何在UICollectionView reloadData后找到的某个cell
- Axure VS Mockplus VS Balsamiq - 原型图设计工具对比
- Android仿iOS7的UISegmentedControl 分段
- 1.3.0 REQUEST ROUTING(请求路由)
- gradle:build.number 获取不到导致的error
- iOS 在UILabel显示不同的字体和颜色
- 用数据库连接池解决org.hibernate.exception.JDBCConnectionException:could not execute query
- UITextFiled的输入框改成一条下划线
- UINvigation,导航条
- [示例]NSDictionary-按value排序数组中的字典并输出(描述器)