I am having a basic question for like best practise.
The setup:
ListViewController: UiTableView with ManagedObjects. The objects will be loaded from a server. First load 20 objects. Scroll to the end of the table, the next 20 objects will be loaded. Selecting a cell will load the DetailViewController. I have a ListObject with an array of the items (and other properties with informations about the list, not relevant for the DetailVC)
DetailViewController: The details of the selected object are shown. The VC also has 2 buttons to show the next object details or the previous object.
Now e.g. there are 20 objects loaded in the ListVC and I select row 10, the DetailVC with Object at index 10 will show. Then I click trough the next objects until object number 20. Now when i click the 'next' Button, the next 20 objects have to be loaded from the server. (Show object #21 but there are only 20 objects loaded).
Is there a best practice to load the next objects? I have a class for data loading. - (void)loadDataWithRequest:completionHandler: When the NSUrlSession DownloadTask finishes, the completionHandler gets called and this calls the class ApiParser for json parsing and adds the result to the List Object.
So i have to call this in the DetailVC for the next 20 objects.
Now what is the best practice to do this? Or is there a better way to implement the data loading?
I could pass a ListVC reference to the DetailVC and call [listvc loadDataWithRequest:completionhandler] and load the detail from [listvc.listobject.items objectAtIndex]
Or i just could pass the ListObjectItems to the detailVC. Somehow load the new objects and have a KVO to the ListObjectItems count.
Other methods would be delegates or NotificationCenter.
But i guess the best practice is not to put the loadData Method in the ListVC, but somewhere else.
How about to put the dataLoad method as instance method in the ListObject class and listen for the KVO in ListVC and DetailVC?
So many possibilities. But what is a good way?