Jean
Jean

Reputation: 2625

Adding new cells 'above' existing ones (rather than 'below') in UITableView

Am a newbie to iOS programming. This is what am trying to do:

  1. The user enters some text in the screen and it keeps getting added to a UITableView.

  2. As usual, it's getting added from the top.

  3. But I want to add it from the bottom i.e. each new message that's added is added above the rest/existing ones, and not below.

Can someone offer some pointer on this please!

Thanks Priya

Upvotes: 0

Views: 47

Answers (2)

Christian Schnorr
Christian Schnorr

Reputation: 10776

Are you using CoreData? If so, maybe you can set a creation time and sort it descending?

If you don't use CoreData but store the data in some sort of array, just add new objects to the beginning of the array and then reload the data.

[array insertObject:data atIndex:0];

Upvotes: 0

atticus
atticus

Reputation: 960

NSMutableArray's -addObject method appends the object to the end of the array. If you want to put it at the beginning, just use this method instead:

[inputArray insertObject:userInput atIndex:0];

There are other ways to put objects in the array and move them around. Take a look at the documentation:

NSMutableArray Documentation

Upvotes: 1

Related Questions