12-27 UITableView常用属性及方法

mac2022-06-30  26

UITableView也有自己的代理协议,它本身继承自UIScrollView

一:代理要遵守代理协议<UITableViewDelegate>,代理协议中的代理方法:

1.改变某一行的行高:(返回是某一索引的行高)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

 

执行完毕后,会使得偶数行的行高为60,奇数行为100;

 

 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

(后面会用到)

// Called after the user changes the selection.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0); 

二:UITableView的常用属性

1、可以用连线的方式设置数据源和代

 self.tableView.dataSource

 self.tableView.delegate

2、设置行高

self.tableView.rowHeight = 60;

@property (nonatomic) CGFloat rowHeight; //default value if unset

@property (nonatomic) CGFloat sectionHeaderHeight// default value if unset

@property (nonatomic) CGFloat sectionFooterHeight// default value if unset

 

3、设置分割线

1).separatorInset属性:

是设定分割线的上左下右的间距的属性,具体代码和效果如下

    self.tableView.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);

    self.tableView.separatorColor = [UIColor blackColor];

 self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

 self.tableView.separatorColor = [UIColor blackColor];

2).设置分割线风格 @property(nonatomic) UITableViewCellSeparatorStyle ;

 

4、设置tableView是否分组(默认在storyboard中已经设置) @property (nonatomic, readonly) UITableViewStyle

UITableViewStylePlain, UITableViewStyleGrouped *separatorColor; style;

5、自定义头和尾部

1)设置头 @property(nonatomic,retain) UIView *tableHeaderView;

 

//above row content. default is nil. not to be confused with section header

 

//给头加一个ContactAdd的按钮

self.tableView.tableHeaderView = [UIButton buttonWithType:UIButtonTypeContactAdd];

效果

@property(nonatomic,retain) UIView *tableFooterView;//content. default is nil. not to be confused with section footer 

转载于:https://www.cnblogs.com/BJTUzhengli/p/5079366.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)