您的位置:首页 > 编程语言

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

2015-12-17 11:20 555 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: