In iOS selected cell should move to top portion in UITableView

后端 未结 4 530
后悔当初
后悔当初 2020-12-20 07:05

I have more than 20 cells in my custom table view, in execution time 6 cells will be visible. Now i select the 4 th cell means, that 4th cell have to come in first position

4条回答
  •  眼角桃花
    2020-12-20 07:41

    As i wrote in the comments:

    Upon selection, move selected arr_CalendarTitle entry to the top of array and call reloadData() on tableView. Table view displays data as is sorted in arr_CalendarTitle.

    moveRowAtIndexPath is not enough, must resort the array too.

    So, before reloadData() call (in button click method), do this:

    id object = [[[arr_CalendarTitle objectAtIndex:int_SelectedIndex] retain] autorelease];
    [arr_CalendarTitle removeObjectAtIndex:int_SelectedIndex];
    [arr_CalendarTitle insertObject:object atIndex:0];
    

    For ARC you can use :

    __autoreleasing id object = [arr_CalendarTitle objectAtIndex:int_SelectedIndex];
    [arr_CalendarTitle removeObjectAtIndex:int_SelectedIndex];
    [arr_CalendarTitle insertObject:object atIndex:0];
    

    Since you have more than one array that holds data (only noticed that now) you must do this for every array thats holds data for tableView cells.

提交回复
热议问题