开发者

Shifting rows in a UITableView

开发者 https://www.devze.com 2023-02-05 05:53 出处:网络
I have looked at several forums and read different threads, but I can\'t seem to find an answer. I\'d really like some help. I have an array that stores Labels whose contents I display in the UITableV

I have looked at several forums and read different threads, but I can't seem to find an answer. I'd really like some help. I have an array that stores Labels whose contents I display in the UITableView's row. The second row cont开发者_开发问答ains fresh data added to the same array and so on. My question is, everytime the labels are displayed in the UITableView, I want it to be displayed on the top row. In essence, the older ones keeps shifting one row down. I understand I need to use: "tableView:moveRowAtIndexPath:toIndexPath:" but it only seems to work with arrays whose contents are strings.


Just to clarify, I'm not displaying each element of the array on a new line. I'm displaying all the elements of the array on a single row, then changing the elements and displaying that as the next row. Except I want the second row to be above the first and so on.


The array you're using is an ordered collection of object, so the easiest way to perform what you're looking fro would be to add the new object in the first position of your array. You can achieve that using the method insertObject:atIndex: of NSMutableArray

ex:

[myArray insertObject:newObject atIndex:0];

This way you don't have to worry about moving your tableView cells ordering.

Hope this helps, Vincent


First of all you don't need to keep the label in some array, you can keep only the string. And when add an new object to the array add it on position 0 and the do and reload of table view.

0

精彩评论

暂无评论...
验证码 换一张
取 消