From bdec1e3094adc892e8d8bdfc909f10ff66c2674a Mon Sep 17 00:00:00 2001 From: Joseph Kuziel Date: Sat, 31 Oct 2015 14:35:37 -0400 Subject: [PATCH] Fixed sorting sections not following sortingEnabled and canDeleteRows flags --- quickdialog/QSortingSection.m | 4 ++-- quickdialog/QuickDialogDataSource.m | 5 +++-- sample/SampleDataBuilder.m | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/quickdialog/QSortingSection.m b/quickdialog/QSortingSection.m index a2333d3b..732eaa77 100644 --- a/quickdialog/QSortingSection.m +++ b/quickdialog/QSortingSection.m @@ -33,7 +33,7 @@ - (QSortingSection *)init { } - (BOOL)needsEditing { - return _sortingEnabled; + return _sortingEnabled || _canDeleteRows; } - (void)fetchValueIntoObject:(id)obj { @@ -58,6 +58,6 @@ - (BOOL)removeElementForRow:(NSInteger)index { } - (BOOL)canRemoveElementForRow:(NSInteger)integer { - return YES; + return _canDeleteRows; } @end diff --git a/quickdialog/QuickDialogDataSource.m b/quickdialog/QuickDialogDataSource.m index 331ae1d7..c9c05e40 100644 --- a/quickdialog/QuickDialogDataSource.m +++ b/quickdialog/QuickDialogDataSource.m @@ -54,7 +54,8 @@ - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInte } - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { - return [[_tableView.root getVisibleSectionForIndex:indexPath.section] isKindOfClass:[QSortingSection class]]; + id section = [_tableView.root getVisibleSectionForIndex:indexPath.section]; + return [section isKindOfClass:[QSortingSection class]] && [section sortingEnabled]; } @@ -85,7 +86,7 @@ - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sou - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { QSection *section = [_tableView.root getVisibleSectionForIndex: indexPath.section]; if ([section isKindOfClass:[QSortingSection class]]){ - return ([(QSortingSection *) section canRemoveElementForRow:indexPath.row]); + return ([(QSortingSection *) section canRemoveElementForRow:indexPath.row]) || ((QSortingSection*)section).sortingEnabled; } return tableView.editing; } diff --git a/sample/SampleDataBuilder.m b/sample/SampleDataBuilder.m index d6e42da4..1143b322 100644 --- a/sample/SampleDataBuilder.m +++ b/sample/SampleDataBuilder.m @@ -610,6 +610,7 @@ + (QRootElement *)createSortingRoot { QSortingSection *sortingSection = [[QSortingSection alloc] init]; sortingSection.key = @"sortedSection"; sortingSection.canDeleteRows = YES; + sortingSection.sortingEnabled = 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"]];