Custom view with data source. When should I request a data source for the first time?

I am creating a custom UIView that has a data source similar to a UITableView . When should this data source query for data for the first time, and in which method of my subclass of UIView ?

Right now I am requesting a data source when it is set in the view property.

I think the table view does it differently, because if I provide its data source in the / xib storyboard and I create the data in the viewDidLoad method of the viewDidLoad controller (the data source is already set by then) then the data source is still will be requested without calling reloadData . When viewing a table reloads data without asking it explicitly?

+4
source share
1 answer

I had a hunch, but I used a debugger to get an authoritative answer. I set a breakpoint in -numberOfSectionsInTableView: and -tableView:numberOfRowsInSection:

They are called from -[UITableView reloadData] , of course, but also from -[UITableView layoutSubviews] . In the special case -[UITableViewController tableView] , -[UITableViewController viewWillAppear:] directly calls -numberOfSectionsInTableView: (iOS 6.1 simulator).

+2
source

Source: https://habr.com/ru/post/1485281/


All Articles