tableView組成:
tableView = 一個(gè)tableView HeaderView + 若干個(gè)section + 一個(gè)tableView FooterView ;
section = 一個(gè)section HeaderView + 若干個(gè)cell + 一個(gè)section FooterView ;
tableView HeaderView:
##這里是我的代碼例子:
tableView FooterView:
##這里是我的代碼例子:
section:
設(shè)置section的數(shù)量:
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView;// Default is 1 if not implemented
##這里是我的代碼例子:
section HeaderView:
設(shè)置section headerView的高度:
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section;
設(shè)置section headerView樣式:
- (nullableUIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section;// custom view for header. will be adjusted to default or specified header height
##這里是我的代碼例子:
section FooterView:
設(shè)置section footerView的高度:
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section;
設(shè)置 section footerView樣式:
- (nullableUIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section;// custom view for footer. will be adjusted to default or specified footer height
##這里是我的代碼例子:
section cell:
設(shè)置cell數(shù)量:
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section;
設(shè)置cell的高度:
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath;
設(shè)置cell的樣式:
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;
##這里是我的代碼例子:
索引:
- (nullableNSArray *)sectionIndexTitlesForTableView:(UITableView*)tableView__TVOS_PROHIBITED;// return list of section titles to display in section index view (e.g. "ABCD...Z#")
##這里是我的代碼例子:
UITableViewStyle:
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style NS_DESIGNATED_INITIALIZER;
其中UITableViewStyle分為以下兩種:
UITableViewStylePlain:
滑動(dòng)tableView時(shí), section(i)的headerView會(huì)保持位置在頂部, 直到下一個(gè)section(i+1)的headerView頂替section(i)的headerView; sectionView的FooterView同理.
UITableViewStyleGrouped:
section的headerView, footerView保持跟tableView一起滑動(dòng).