Skip to content

Commit

Permalink
Merge pull request escoz#668 from luketheobscure/delete_support
Browse files Browse the repository at this point in the history
Notify QuickDialogController when tableViewCell will be deleted
  • Loading branch information
escoz committed Apr 13, 2014
2 parents c27fd07 + 76de93c commit 8394bb2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions quickdialog/QuickDialogController.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@

+ (QuickDialogController *)controllerForRoot:(QRootElement *)root;

/**
Called before a cell is removed from the tableView.
*/
- (void)willDeleteElement:(QElement *)element;

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


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

- (void)willDeleteElement:(QElement *)element{
// Intentionally empty.
}

- (void) resizeForKeyboard:(NSNotification*)aNotification {
if (!_viewOnScreen)
Expand Down
10 changes: 10 additions & 0 deletions quickdialog/QuickDialogDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
QSortingSection *section = ((QSortingSection *) [_tableView.root getVisibleSectionForIndex: indexPath.section]);

QElement *element;
if (section.elements.count >= indexPath.row) {
element = section.elements[indexPath.row];
}

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

if ([section removeElementForRow:indexPath.row]){
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
Expand Down
4 changes: 4 additions & 0 deletions sample/ExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ - (void)displayViewControllerForRoot:(QRootElement *)element {
}
}

-(void)willDeleteElement:(QElement *)element{
// Optionally you could remove the element from your data source here.
}


-(void)setTheme:(QElement *)element {

Expand Down
1 change: 1 addition & 0 deletions sample/SampleDataBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ + (QRootElement *)createSortingRoot {

QSortingSection *sortingSection = [[QSortingSection alloc] init];
sortingSection.key = @"sortedSection";
sortingSection.canDeleteRows = YES;
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"First" Value:@"1"]];
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"Second" Value:@"2"]];
[sortingSection addElement:[[QLabelElement alloc] initWithTitle:@"Third" Value:@"3"]];
Expand Down

0 comments on commit 8394bb2

Please sign in to comment.