UITableView 01
2016-05-04 22:48
375 查看
UITableView
tableView
要显示数据的时候,
要依赖数据源代理
必须实现三个方法
1.
tableView中
有多少组
numberOfSectionsInTableView:
2.
每一组有多少行
numberOfRowsInSection:
3.
每一行要显示的内容
cellForRowAtIndexPath:
//
设置组头和组尾
的
文本
titleForHeaderInSection:
titleForFooterInSection:
//
设置
组头view的高度
_tableView.sectionHeaderHeight
=
100;
//
设置
组尾view的高度
_tableView.sectionFooterHeight
=
50;
1.选中某一个cell的时候,
就会调用这个方法
- (void)tableView:(UITableView
*)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
}
2. 取消选中会自动调用这个方法
- (void)tableView:(UITableView
*)tableView didDeselectRowAtIndexPath:(NSIndexPath
*)indexPath {
}
tableViewCell
的重用机制
tableView
自身维护了一个缓存池
1.
定义重用标识符
2.
根据重用标识符到缓存中去找对应的cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
3.
对取到的cell
进行判断,
如果找不到就重新实例化cell
实例化的时候,
一定要设置重用标识符
: identifier
if
(nil
== cell ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
注意:
1.
一定要先修改数据源中的数据
2.
进行刷新
1.
刷新全部数据
[_tableView reloadData];
2.
刷新指定行
的
数据
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
[_tableView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationLeft];
//
是否隐藏
tableView
的状态栏
- (BOOL)prefersStatusBarHidden {
return
YES;
}
tableView
要显示数据的时候,
要依赖数据源代理
必须实现三个方法
1.
tableView中
有多少组
numberOfSectionsInTableView:
2.
每一组有多少行
numberOfRowsInSection:
3.
每一行要显示的内容
cellForRowAtIndexPath:
//
设置组头和组尾
的
文本
titleForHeaderInSection:
titleForFooterInSection:
//
设置
组头view的高度
_tableView.sectionHeaderHeight
=
100;
//
设置
组尾view的高度
_tableView.sectionFooterHeight
=
50;
1.选中某一个cell的时候,
就会调用这个方法
- (void)tableView:(UITableView
*)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath {
}
2. 取消选中会自动调用这个方法
- (void)tableView:(UITableView
*)tableView didDeselectRowAtIndexPath:(NSIndexPath
*)indexPath {
}
tableViewCell
的重用机制
tableView
自身维护了一个缓存池
1.
定义重用标识符
2.
根据重用标识符到缓存中去找对应的cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
3.
对取到的cell
进行判断,
如果找不到就重新实例化cell
实例化的时候,
一定要设置重用标识符
: identifier
if
(nil
== cell ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
}
注意:
1.
一定要先修改数据源中的数据
2.
进行刷新
1.
刷新全部数据
[_tableView reloadData];
2.
刷新指定行
的
数据
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
[_tableView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationLeft];
//
是否隐藏
tableView
的状态栏
- (BOOL)prefersStatusBarHidden {
return
YES;
}
相关文章推荐
- 347. Top K Frequent Elements-获得前K高次元素
- UIWindow
- iOS开发报错CUICatalog: Invalid asset name supplied: (null)
- UI进阶 数据处理之文件读写
- Rescue HDU1242 (BFS+优先队列)
- FZU 2037 Maximum Value Problem【递推】
- This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' 错误解决
- POJ 2524 Ubiquitous Religions
- 让多语言本地化变得更简单的Xcode插件——AMLocalizedStringBuilder
- 【arduino】通过Esp8266-01模块实现的WiFi通信(2)与电脑的连接和烧写
- "围观"设计模式(9)--创建型之创建者模式(Builder Pattern)
- [暴力] BZOJ 3917 [Baltic2014]sequence
- 关于valueOf和toString
- UIMotionEffect和Home页背景视差效果
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
- Android 中的UI第一篇:Common Layout
- 聊一聊CommonJS,Requirejs,SeaJS,AMD,CMD之间需要理清的关系
- The Donkey of Gui Zhou驴和老虎是否相遇问题(hdu4704)
- 51单片机与Arduino通过nrf24l01无线模块通信
- poj 1458 Common Subsequence