UITableView的HeaderView和FooterView


header通過下面兩個代理方法設置

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

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

footer通過下面兩個

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

 

如果要做整個tableview的header和footer,要通過tableview setHeaderView setFooterView

 

如果只是指定每個section的title,只需要tableView的dataSource的實現下面的方法來返回每個section的title

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

 

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

是用來自定義每個section的headView

 

 

如果是要自定義每個section的headView用第二個方法創建自定用的視圖並返回。

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

if(section == 0) { CustomView *view = [[CustomeView alloc] init]; return [view autorelease]; }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM