开发者

Reordering rows in a UITableView

I've been stuck for a really long time with this problem and I need help. Here's what my code does. I have an NSMutableArray with data. The first row displays all the elements of the array. Then I remove the old data and add fresh data to my array. Then I display this in the second row and so on.

What I'd like to know is, how to display my dat开发者_StackOverflow中文版a such that when I display the data for the second row, I'd like the first row to shift one row down and the second row to be displayed in the first row and so on. For example:

1st call:

abcd (row 1)

2nd call:

efgh (row 1) abcd (row 2)

3rd call:

ijkl (row 1)

efgh (row 2)

abcd (row 3)

and so on.

Please note, a is the first element of the array, b the second, c the third and so on. It isn't a single string. I've done this for several reasons.

Any help would be appreciated!


In cellForRowAtIndexPath code as follows,

int index=[mutArray count]-indexPath.row-1;

[mutArray objectAtIndex:index];


Your array should contain -- let say

{ijkl,efgh,abcd}

then in the table view delegate for any row

int totalCount = [array count];
int startIndex = totalCount - (rowIndex+1); //rowIndex -- row index delegate is called

for(i = startIndex; i<totalCount ; i++)
{
//objectAtIndex
//display the objects from  startIndex to totalCount in the cell
}

Output: row 1: rowIndex == 0 totalCount = 3 startIndex = 2 --> abcd

row 2: rowIndex == 1 totalCount = 3 startIndex = 1 --> efgh abcd

row 3: rowIndex == 2 totalCount = 3 startIndex = 0 --> ijkl efgh abcd


A small clarification, the contents of my array are determined only at runtime. Each element of the array is a label. So row one will be: label 1,label 2,label3 ... Then the array contents are deleted and new labels are added. So now, row 0: label 4,label5, label 6 row 1: label 1,label 2,label 3

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜