Reordering rows in tableView while not in editing mode [duplicate]

折月煮酒 提交于 2019-12-10 09:24:39

问题


In my app I have implemented the option to re-order rows, but I am using the default edit button to show the delete button and the three lines icon to move the row. But I have seen an iOS app that allows the user to move rows directly, without need to enter the edit mode. I would appreciate any advice to implement that way to allow re-ordering rows directly, not using the edit mode. Thank you.


回答1:


You need to implement both

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
- (BOOL)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath

and have your table view editing set to YES in order for the reorder controls to show.




回答2:


use moveRowAtIndexPath:toIndexPath: UITableView method

UITableView implements below method.Use it to move rows, or chain them to have some animation of row by row.

- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath

read in detail about it in Apple documentation.




回答3:


Try to load this from end of your -viewDidLoad:

self.editing = NO;
[self editTable:nil];

editTable: is method action of edit button.



来源:https://stackoverflow.com/questions/21902483/reordering-rows-in-tableview-while-not-in-editing-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!