Skip to content

Commit

Permalink
Merge pull request escoz#670 from luketheobscure/delete_support
Browse files Browse the repository at this point in the history
Change willDeleteElement: to shouldDeleteElement:
  • Loading branch information
escoz committed Apr 14, 2014
2 parents 7742c4e + f5aae3c commit b1ab112
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions quickdialog/QuickDialogController.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
+ (QuickDialogController *)controllerForRoot:(QRootElement *)root;

/**
Called before a cell is removed from the tableView.
Called before a cell is removed from the tableView. Return YES and QuickDialog will delete the cell, return NO if you want to delete the cell or reload the tableView yourself.
*/
- (void)willDeleteElement:(QElement *)element;
- (BOOL)shouldDeleteElement:(QElement *)element;

+ (UINavigationController *)controllerWithNavigationForRoot:(QRootElement *)root;

Expand Down
4 changes: 2 additions & 2 deletions quickdialog/QuickDialogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ - (QuickDialogController *)controllerForRoot:(QRootElement *)root {
return [QuickDialogController buildControllerWithClass:controllerClass root:root];
}

- (void)willDeleteElement:(QElement *)element{
// Intentionally empty.
- (BOOL)shouldDeleteElement:(QElement *)element{
return YES;
}

- (void) resizeForKeyboard:(NSNotification*)aNotification {
Expand Down
6 changes: 4 additions & 2 deletions quickdialog/QuickDialogDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
element = section.elements[indexPath.row];
}

if ([element.controller respondsToSelector:@selector(willDeleteElement:)]) {
[(QuickDialogController *)element.controller willDeleteElement:element];
if ([element.controller respondsToSelector:@selector(shouldDeleteElement:)]) {
if (![(QuickDialogController *)element.controller shouldDeleteElement:element]) {
return;
};
}

if ([section removeElementForRow:indexPath.row]){
Expand Down
5 changes: 3 additions & 2 deletions sample/ExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ - (void)displayViewControllerForRoot:(QRootElement *)element {
}
}

-(void)willDeleteElement:(QElement *)element{
// Optionally you could remove the element from your data source here.
-(BOOL)shouldDeleteElement:(QElement *)element{
// Return no if you want to delete the cell or redraw the tableView yourself
return YES;
}


Expand Down

0 comments on commit b1ab112

Please sign in to comment.