码迷,mamicode.com
首页 > 其他好文 > 详细

表格视图 - 使用代码自定义行高度

时间:2015-12-17 12:18:04      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

1. 实现UITableViewDelegate协议

@interface ViewController () <UITableViewDelegate>

 

2. 将表格视图的代理属性指向其父容器视图

self.myTableView.delegate = self;

 

3. 实现协议对应的方法

tableView:heightForRowAtIndexPath:

 

完整代码(ViewController.m):

#import "ViewController.h"

@interface ViewController () <UITableViewDelegate>
@property (nonatomic, strong) UITableView *myTableView;
@end

@implementation ViewController
    
- (CGFloat)     tableView:(UITableView *)tableView
  heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([tableView isEqual:self.myTableView]){
        return 100.0f;
    }
    return 40.0f;
}
    
- (void)viewDidLoad{
    [super viewDidLoad];
    
    self.myTableView = [[UITableView alloc]
                        initWithFrame:self.view.bounds
                        style:UITableViewStylePlain];
    
    self.myTableView.delegate = self;
    
    [self.view addSubview:self.myTableView];
    
}

@end

 

表格视图 - 使用代码自定义行高度

标签:

原文地址:http://www.cnblogs.com/davidgu/p/5053484.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!