简体   繁体   中英

UITableView doesn't show bars to move the cells

I tried to implement this method in order to be able to move the cells in my Tableview. And everything runs well but the bars aren't shown and I'm not able to move the cells.

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


[[HPPossessionStore defaultStore] movePossessionAtIndex:[indexPath row] toIndex:[newIndexPath row]];

}

What do I have to do to make it work?

Add below delegate method as well.

- (BOOL)tableView:(UITableView *)tableView 
canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

This solved my problem, although I have no idea why. If someone could explain it I would be very thankful.

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
 [[HPPossessionStore defaultStore] movePossessionAtIndex:[fromIndexPath row] toIndex:[toIndexPath row]];
}

It is explained in more detail here: https://stackoverflow.com/a/20786785/2310837

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM