How can I subclass a UITableView?

前端 未结 3 1732
小鲜肉
小鲜肉 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条回答
  •  执笔经年
    2020-12-19 11:13

    I think, you should still go with a Controller class. I expect subclassing UITableView to be tedious work — if possible with reasonable amount at all.

    There is no problem to have UIViewController/NoViewController implemented the delegate and datasource and yet assign another controller to a specific tableView. note, that the datasource and delegate don't need to be subclasses of UITableViewController.

    have a look at this answer: Implement Delegate at Run Time?

    My UITableView does not delegate to its view controller, so that's not the problem.

    You have to have to use delegate and datasource, that is how TableViews are filled and configured. otherwise you will have to overwrite every method of UITableView — including private ones, a no-go if you want into AppStore. Recreating UITableView without subclassing it would be even easier.

提交回复
热议问题