美文网首页iOS
UITableView常用的代理方法

UITableView常用的代理方法

作者: LSRain | 来源:发表于2019-05-04 22:23 被阅读0次

提要

本文主要介绍UITableView常用的几个代理与数据源方法,方便在项目开发中进行快速的拷贝复用。当然,也可以把常用的这些常用的方法整理成代码块快速调用,或查询UITableView的官方API,找到需要使用的方法,使用如下快捷键可快速查询系统类API:

coomand + shift + o

2019-05-04_22-14-28

UITableView常用代理及数据源

#pragma mark - UITableView delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return cellHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return headerViewHeight;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

    return FooterViewHeight;
}

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

    return nil; /// headerView
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    return nil; /// FooterView
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    /// 点击cell
}

#pragma mark - UITableView DataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return cellCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return cell; /// 返回cell !注意要先注册cell
}

文章发布

本文同步发布至:
简书
LSRain

相关文章

网友评论

    本文标题:UITableView常用的代理方法

    本文链接:https://www.haomeiwen.com/subject/pxfqoqtx.html