自定义 tableView的初始化方法(作为自己日志)

本文介绍了两种自定义初始化UITableView的方法。方法1中,通过指定frame、样式和数据源及代理控制器来创建表格视图。方法2则调用了方法1,并进行了数据源数组的初始化。在实际使用中,可以通过调用方法2并传入所需的样式来设置表格。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


方法1:

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style controller:(id<UITableViewDataSource, UITableViewDelegate>)controller

{
    if (self = [super initWithFrame:frame style:style]) {
        //指定代理类为传进来的 VC类
        self.dataSource = controller;
        self.delegate = controller;
        //添加controller上面
        
        UIViewController *vc = (UIViewController *)controller;
        [vc.view addSubview:self];
    }
    return self;

}


方法2调用方法1;

- (void)createTableView:(UITableViewStyle)style
{
    //数据源数组初始化
    _dataArray = [NSMutableArray array];
    //初始化
    _tableView = [[LQTableView alloc] initWithFrame:PCH_Bounds style:style controller:self];
}



执行方法2;

[self createTableView:UITableViewStylePlain];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值