UITableView的代理方法

一、点击某个cell调用     

/**
 * 点击了第几行调用
 */
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"点击了第%zd行",indexPath.row);
}

二、取消被选择的那一行

/**
 * 取消了被选择的那一行
 */
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"取消了%zd行",indexPath.row);
}

三、第indexPath行cell的高度,与self.ttableView.rowHeight相比,区别在于self.ttableView.rowHeight设置所以cell一样高度

/**
 * 第indexPath行cell的高度
 */
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row %2 ==0){
        return 100;
    }else{
        return 50;
    }
}

四、第section组头部显示

/**
 * 返回第section组头部高度
 */

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}
/**
 * 告诉tableView第section组显示怎样的头部控件
 */
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIButton buttonWithType:UIButtonTypeContactAdd];
}
原文地址:https://www.cnblogs.com/xsphehe/p/5614208.html