简体   繁体   中英

Using a custom UITableView in UIViewController

So I had a VC that was 700+ lines of code so I decided to refactor and throw all the table view logic into it's own class. I thought this would be very similar to making a custom UITableViewCell. I made the custom class and copy pasted all the functionality I had in the VC. In the storyboard I changed the class from UITableView to my custom class. Removed my VC as the delegate and datasource.

However, when I run it, the app loads but the tableView is empty.

Any ideas I missing something vital here?

Views are stupid. Views should not manage content. Instead they should present content set from the outside in a reusable way. A view with static content isn't really usable.

If you want to subclass UITableView to manage colors, insets, go for it. But its content should not be managed by itself, but instead by a controller.

Have you set the tableView's dataSource and delegate to your new subclass? Essentially, to self ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM