Reputation: 1089
I know this has been asked before, but the usual fixes (implementing both the delegate and datasource methods, setting the delegate and datasource appropriately etc) didn't work. I am absolutely stumped here.
Despite having set the delegate and datasource, setting the tableView to editing, telling the cell to show the reorder control and implementing the required methods, the reorder control will not show. The tableView goes into editing mode as I can see the delete controls. But the reorder control never shows and I can't reorder the cells.
I've even stripped out all my custom cell loading and customisation in case something there was causing the problem. I just have no idea what's going wrong. What's strange is that tableView:canMoveRowAtIndexPath:
doesn't seem to be called, as the log never appears in the console.
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame style:UITableViewStyleGrouped];
if (self) {
self.delegate = self;
self.dataSource = self;
self.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.0];
self.separatorInset = UIEdgeInsetsZero;
self.delaysContentTouches = NO;
[self loadImagePicker];
[self registerClass:[ExpandingTitleTableViewCell class] forCellReuseIdentifier:[ExpandingTitleTableViewCell reuseIdentifier]];
[self registerClass:[SliderTableViewCell class] forCellReuseIdentifier:[SliderTableViewCell reuseIdentifier]];
[self registerClass:[UndoRedoTableViewCell class] forCellReuseIdentifier:[UndoRedoTableViewCell reuseIdentifier]];
[self registerClass:[NudgeImageTableViewCell class] forCellReuseIdentifier:[NudgeImageTableViewCell reuseIdentifier]];
self.alwaysBounceVertical = NO;
self.editing = YES;
}
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *reuseIdentifier = nil;
Class cellClass = nil;
//Custom cell class setting code was here
reuseIdentifier = @"Cell";
cellClass = [UITableViewCell class];
//Cell customisation code was here
cell.showsReorderControl = YES;
return cell;
}
- (void)moveRowAtIndexPath:(NSIndexPath *)indexPath toIndexPath:(NSIndexPath *)newIndexPath {
//TBC
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Can move row");
return YES;
}
Upvotes: 2
Views: 494
Reputation: 1089
Ahh, figured it out. I was overriding the wrong method. I overrode moveRowAtIndexPath:toIndexPath:
, not tableView:moveRowAtIndexPath:toIndexPath:
. The first is presumably the method on UITableView
which actually moves the row. It appeared in autocomplete because this tableView is its own delegate and datasource. I've implemented the correct method and it works now.
Upvotes: 3