Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have worked on an app that deals with a very similar problem that i was able to solve. I was expecting a complicated solution but it was really simple. Here is how you can solve it:</p> <p>1) Create a new array in which you will receive new items and call it let us say 'moreItems', also synthesise it of course. </p> <pre><code>@property (nonatomic, readonly) NSMutableArray *moreItems; </code></pre> <p>2) In viewDidLoad of the ViewController that is linked with your TableView or CollectionView, alloc/init this array:</p> <pre><code>moreItems = [[NSMutableArray alloc] init]; </code></pre> <p>3) Now you need to add your existing array let us say it was "items" to the new array that you have just created named 'moreItems'. You can do this using 'addObjectsFromArray'</p> <pre><code>[moreItems addObjectsFromArray:[channel items]]; </code></pre> <p>'channel items' contains the objects it has received earlier and it will add these items to the newly created array called 'moreItems'. I am assuming you are collecting data from some web service, so you can implement this step in connectionDidFinsihLoading.</p> <p>4) Now change your data source of TableView/CollectionView and replace it with the new array that is 'moreItems'</p> <p>5) Next issue is that you don't want to reload the whole tableview and want to deal with new items. To have this functionality, you need to persist items. You can use archiving or core data whatever you are comfortable with.</p> <p>6) The items that are already fetched, you will have to persist them let us say with archiving. And show them in the tableview when the user opens the app while it grabs more items that are updated on the web service.So first show the persisted items immediately and then handle the new items.</p> <p>7) You need to look for some unique object, in my case it was the 'link' as every item has a different link and i can sort and handle them on this basis. You also need to use </p> <pre><code>- (BOOL) isEqual:(id)object </code></pre> <p>to compare the links on the web service and the links that are already in the tableview. This step is necessary because then your app won't add the items with links that are already in the tableview.</p> <p>8) If there is some date associated with each item, you can use that date to sort them and show the new ones on top by using 'sortUsingComparator'</p> <p>9) Also you need to use "[[self tableView] insertRowsAtIndexPath:rows withRowAnimation:UITableViewRowAnimationTop" to have that effect that shows user the new items have been added on top of the earlier ones.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload