IOS界面UI设计5之UITableView的基本属性(一)
2014-11-11 19:26
363 查看
下面对UITableView的基本属性做一下概括:
(1)两种风格,一种扁平风格,一种分组风格
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
@property (nonatomic,
readonly) UITableViewStyle style;
只有扁平风格才能实现向上滑动的时候,section动态更新。
(2)UITableViewController UITableView 一个是视图控制器,一个是视图。视图控制器默认实现了下面的一些代理方法。UITableView是继承UIScrollView。
(3)两个代理方法
UITableViewDataSource,
UITableViewDelegate。一个代理方法实现数据源的代理,一个实现了UITableView回调方法的代理。
(4)UITableView回调方法
调用数据源的下面方法得知一共有多少组数据
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
调用数据源的下面方法得知每一组有多少行数据
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;
调用数据源的下面方法得知每一行显示什么内容
- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
显示头部标题
- (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section
设置每一行以及UITableView的head和foot的高。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
(5)cell属性设置
typedef
NS_ENUM(NSInteger, UITableViewCellAccessoryType) {
UITableViewCellAccessoryNone,
// don't show any accessory view
UITableViewCellAccessoryDisclosureIndicator,
// regular chevron. doesn't track
UITableViewCellAccessoryDetailDisclosureButton,
// info button w/ chevron. tracks
UITableViewCellAccessoryCheckmark,
// checkmark. doesn't track
UITableViewCellAccessoryDetailButton
NS_ENUM_***AILABLE_IOS(7_0)
// info button. tracks
};
(6)ContentView
每一个UITableView下都有一个子view,这个view就叫ContentView,其中包含:TextLabel、DetailTextLabel、UIImageVIew。
(7)对UITableView初始化的时候,可以设置cell的风格
typedef
NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
(8)设置UITableView的头部以及底部View
self.tableView.tableHeaderView self.tableView.tableFooterView
(9)设置分隔符以及背景颜色
self.tableView.separatorStyle =
UITableViewCellSeparatorStyleNone;
self.tableView.separatorColor
(10)cell重用机制
static
NSString *ID = @"hero";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:ID];
if (cell ==
nil){
cell = [[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:ID];
}
(11)数据刷新
[self.tableViewreloadData];全部刷新
NSIndexPath *path = [NSIndexPath
indexPathForRow:row
inSection:0];
[self.tableView
reloadRowsAtIndexPaths:@[path]
withRowAnimation:UITableViewRowAnimationBottom];
局部刷新
(12)添加索引数据(注意这里设置的要和section的title一致)
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
(13)隐藏当前应用的标题栏
- (BOOL)prefersStatusBarHidden
{
return
YES;
}
(1)两种风格,一种扁平风格,一种分组风格
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style;
@property (nonatomic,
readonly) UITableViewStyle style;
只有扁平风格才能实现向上滑动的时候,section动态更新。
(2)UITableViewController UITableView 一个是视图控制器,一个是视图。视图控制器默认实现了下面的一些代理方法。UITableView是继承UIScrollView。
(3)两个代理方法
UITableViewDataSource,
UITableViewDelegate。一个代理方法实现数据源的代理,一个实现了UITableView回调方法的代理。
(4)UITableView回调方法
调用数据源的下面方法得知一共有多少组数据
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
调用数据源的下面方法得知每一组有多少行数据
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;
调用数据源的下面方法得知每一行显示什么内容
- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
显示头部标题
- (NSString *)tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section
设置每一行以及UITableView的head和foot的高。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
(5)cell属性设置
typedef
NS_ENUM(NSInteger, UITableViewCellAccessoryType) {
UITableViewCellAccessoryNone,
// don't show any accessory view
UITableViewCellAccessoryDisclosureIndicator,
// regular chevron. doesn't track
UITableViewCellAccessoryDetailDisclosureButton,
// info button w/ chevron. tracks
UITableViewCellAccessoryCheckmark,
// checkmark. doesn't track
UITableViewCellAccessoryDetailButton
NS_ENUM_***AILABLE_IOS(7_0)
// info button. tracks
};
(6)ContentView
每一个UITableView下都有一个子view,这个view就叫ContentView,其中包含:TextLabel、DetailTextLabel、UIImageVIew。
(7)对UITableView初始化的时候,可以设置cell的风格
typedef
NS_ENUM(NSInteger, UITableViewCellStyle) {
UITableViewCellStyleDefault,
UITableViewCellStyleValue1,
UITableViewCellStyleValue2,
UITableViewCellStyleSubtitle
};
(8)设置UITableView的头部以及底部View
self.tableView.tableHeaderView self.tableView.tableFooterView
(9)设置分隔符以及背景颜色
self.tableView.separatorStyle =
UITableViewCellSeparatorStyleNone;
self.tableView.separatorColor
(10)cell重用机制
static
NSString *ID = @"hero";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:ID];
if (cell ==
nil){
cell = [[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:ID];
}
(11)数据刷新
[self.tableViewreloadData];全部刷新
NSIndexPath *path = [NSIndexPath
indexPathForRow:row
inSection:0];
[self.tableView
reloadRowsAtIndexPaths:@[path]
withRowAnimation:UITableViewRowAnimationBottom];
局部刷新
(12)添加索引数据(注意这里设置的要和section的title一致)
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
(13)隐藏当前应用的标题栏
- (BOOL)prefersStatusBarHidden
{
return
YES;
}
相关文章推荐
- IOS学习 UITableView 基本属性
- IOS界面UI设计6之UITableView团购、微博(二)
- IOS UITableView的相关属性和方法
- ios uitableview里点击界面退出键盘的实现和一些疑惑
- iOS:UITableView 使用(一)--基本使用
- UITableView中的代理方法的含义以及它的基本属性
- iOS开发UI篇—在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建
- iOS tableView 控件用法 [0] UITableView的基本用法
- ios--UITableview的基本使用方法
- iOS:UITableView 方法 属性 详解
- iOS开发UI篇—在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建
- iOS开发UI篇—在UITableview的应用中使用动态单元格来完成app应用程序管理界面的搭建
- IOS学习:基本控件(UITableView)
- IOS UITableView 方法及属性学习
- IOS UITableView NSIndexPath属性讲解
- IOS UITableView 方法及属性学习
- UITableView基本属性详解
- 给iOS开发新手送点福利,简述UITableView的属性和用法
- IOS开发---菜鸟学习之路--(十七)-利用UITableView实现个人信息界面
- iOS UITableView NSIndexPath属性讲解