您的位置:首页 > 产品设计 > UI/UE

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: