How can I subclass a UITableView?

前端 未结 3 1738
小鲜肉
小鲜肉 2020-12-19 10:34

I want to subclass a UITableView as I want to create a reusable table view component in my application.

The idea is instead of using a delegate for say cellForRowA

3条回答
  •  Happy的楠姐
    2020-12-19 11:14

    If I understood you, you need this class declaration:

    @interface ShareUITableView : UITableView 
    

    And then, in your class constructor, you should assign the instance itself as its own datasource:

    - (id)init
    {
        //...
        self.dataSource = self;
        //...
    }
    

    Of course, the class will have to adopt the protocol.

    Good luck!

提交回复
热议问题