Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I know how to insert objects into a table using...

[self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];

And how to reload/delete/move rows using the corresponding methods.

So, my question...

I have an array @[@"apple", @"banana", @"pear", @"strawberry"] that is already in the table and I download some new data in the form of this array...

@[@"orange", @"raspberry"]

How should I insert these into the table so that the order remains?

In the end I want this...

@[@"apple", @"banana", @"orange", @"pear", @"raspberry", @"strawberry"]

So, I can't just merge and sort the arrays as I'd lose the indices of where things have been inserted.

I don't want to just merge and reload data as you lose the animations.

If for instance I iterate the array and do...

//begin updates

//insert object @"orange" at index 2

//insert object @"raspberry" at index 4

//end update

then are the adjusted indices taken in to consideration? i.e. if I add them the other way around then @"raspberry" would be added at index 3 not 4. Does the table view work with this adjustment on the fly?

share|improve this question

closed as unclear what you're asking by 0x7fffffff, Josh Caswell, dreamlax, Krishnabhadra, RGraham Aug 9 '13 at 7:08

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Would love to see a valid comment for the down vote. – Fogmeister Aug 8 '13 at 10:32

1 Answer 1

up vote 1 down vote accepted

you can take temp array in which merge both array and sort .

then get index of last added array object and using that you can make indexset and add row in table and also add that object in your table datasource array.

may be this work for you..

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.