UITableView的常用方法和属性
来源:互联网 发布:登录别人淘宝有提示吗 编辑:程序博客网 时间:2024/05/20 20:22
以下总结的方法和属性,是我自己在平时的开发中经常使用到的,实用性很强,红字的是比较重要却又不太好记住的方法,大家可以拿去看一下!如果哪里出现错误,欢迎指出来,大家一起讨论学习!
首先是tableView两个代理的常用方法:
1.UITableViewDelegate的方法
1>点击某个cell执行什么操作的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}
2.UITableViewDataSource的方法
1>有几个组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{}
2>每个组有几个cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{}
3>每个组的每个cell里面的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{}
//设置section的头部标题(尾部标题Footer)
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {}
//设置头部视图(尾部视图footerView)
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {}
3.UItableView的常用方法
//重新加载tableView,刷新全局
[self.tableView reloadData];
//重新加载tableView中部分的cell
[self.tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationLeft];
如何获取当前模型呢 就要获取当前cell的索引 方法如下
NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow];
//专门获取组的索引的方法,需要给headerView设置一个tag,headerView.tag=section
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:headerView.tag];
//刷新指定组的方法
[self.tableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationLeft];
//获得最后一行的索引
NSIndexPath *lastPath = [NSIndexPath indexPathForRow:self.messageFrame.count- 1 inSection:0];
//让tableView滚动到哪一行的哪个部位
[self.tableView scrollToRowAtIndexPath:lastPathatScrollPosition:UITableViewScrollPositionBottom animated:YES];
4.UITableViewCell的常用属性
// 设置cell上面三个子控件
cell.imageView.image = [UIImage imageNamed:hero.icon];
cell.textLabel.text = hero.name;
cell.detailTextLabel.text = hero.intro;
cell的类型 :UITableViewCellStyle
cell的分割线类型:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
cell被选中的类型:UITableViewCellSelectionStyle
cell的尾部按钮类型(辅助样式):UITableViewCellAccessoryType
cell不允许点击 : self.tableVIew.allowsSelection = NO;
// 自定义辅助指示器
cell.accessoryView = [UIButton buttonWithType:UIButtonTypeContactAdd];
//要想cell透明来显示tableView的背景图片 就要把颜色设成ClearColor
cell.backgroundColor = [UIColor ClearColor];
// 设置cell默认状态的背景视图
cell.backgroundView = imageView;
// 设置cell选中时的背景视图
cell.selectedBackgroundView = imageView;
//创建(返回)索引栏
- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView*)tableView {
NSMutableArray * arrM = [NSMutableArray array];
for (RCGroups *group in self.groups) {
[arrM addObject:group.title];
}
return arrM;
}
- UITableView的常用方法和属性
- UITableView常用属性和方法
- UITableView和UITableViewCell常用属性和方法
- UITableView常用属性和方法基础
- UITableView的属性和方法
- UITableView的属性和方法
- iOS UITableView的一些常用属性,方法
- UITableView的常用属性
- UITableView常用方法、属性总结
- UITableView里面的属性和方法总结
- ios开发总结之UITableView常用属性和方法
- UITableView的常用方法
- UITableView常见属性和方法
- UITableView 相关属性和方法
- IOS UITableView 常用方法及属性
- UIScrollView & UITableView 一些常用方法与属性
- UITableView Cell的属性方法
- UITableView常用属性和一些小知识点
- 278. First Bad Version
- Android Studio编译错误汇总
- 政治常识扫盲
- 欢迎使用CSDN-markdown编辑器
- 第三次实验:安装pig
- UITableView的常用方法和属性
- C语言中 sizeof 运算的值是在编译时还是运行时确定的?
- 机器视觉中的图像积分图及其实现
- 关于一个时间补充的问题
- Civilization V and Beyond Earth
- 关于部门后端全部转向java前初步设想
- 使用drawerLayout布局报错
- Andorid通话设置界面添加perference
- ubuntu14.04下caffe只用CPU跑,熟悉一下