The UITableViewController subclass implements the UIDataSourceModelAssociation protocol, but its methods are never called

My application uses the Stanford CoreDataTableViewController course, which is a subclass of UITableViewController.

For individual views of my application, I create subclasses of CoreDataTableViewController to control a specific view.

I recently hooked up encoding and state recovery throughout my application, and it all seems to work fine. The only thing I was late was to implement the UIDataSourceModelAssociation protocol to supposedly save the visible and selected rows of UITableViews (I also hoped that it would save the editing state of the table view and the specific row if I chose to delete it but havenโ€™t confirmed yet).

I implemented UIDataSourceModelAssociation in the CoreDataTableViewController, hoping that it will just work for all my views, but when debugging it does not work, and adding breakpoints I see that neither of the two UIDataSourceModelAssociation methods ever gets called when I put my application in the background mode using the "home" button or restore it when you restart it in Xcode.

The CoreDataTableViewController and my subclasses from it implement some dataSource methods to actually display the rows in my table view. I searched and found that the UITableViewController automatically adds itself as a dataSource for tableView.

I have added common sense statements to my subclasses of the viewDidLoad form function

assert(self.tableView); assert(self.tableView.dataSource == self); <--- fails here 

What fails when checking the data source itself. I can see, registering and using the debugger, that the dataSource is not zero at the moment.

I guess I was just wondering if the class has a subclass of the class, each class has the same self value, or is it because my UITableViewController has set itself as a data source, but by the time I subclassed it twice before my specific instance The view itself is a little different than the parent UITableViewController. Or something else intercepts the dataSource and forwards as needed. As a correction, I should consider hardcoding my own subclass for myself or have a CoreDataTableViewController, which explicitly adds itself as a dataSource, since the UIDataSourceModelAssociation methods are implemented here.

For reference, my view hierarchy consists of my subclasses of UITableViewController living inside navigation controllers, which I heard might cause problems.

Just a little clarity about how a subclassification should work with respect to its own class pointers, and wonders if anyone can understand why my protocol methods are not being called, would really be appreciated.

Greetings

+6
source share
1 answer

I'm still not sure why my DataSource TableViewController is not directly configured for itself. But obviously, my dataSource methods are called my tableView functions. Obviously, some kind of object is sending dataSource methods to my actual class for me ...

Ultimately, getting the UIDataSourceModelAssociation protocol methods was as simple as ensuring that the UITableViewController and UITableView inside it have recovery identifiers .. only with an external UITableViewController having a recovery identifier, none of these methods are called.

Unfortunately, these methods are now fooling me, called before my UIManagedDocument has finished loading, so I really can't do anything useful with them. This is another problem.

+1
source

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


All Articles