From 7c10f10f3f563e84b335e47e61f3bef2516a0a4a Mon Sep 17 00:00:00 2001 From: Eduardo Scoz Date: Mon, 27 Feb 2012 08:48:24 -0600 Subject: [PATCH] Fixes sorting of elements. --- QuickDialog.xcodeproj/project.pbxproj | 8 ++++++++ quickdialog/NSMutableArray+MoveObject.h | 7 +++++++ quickdialog/NSMutableArray+MoveObject.m | 19 +++++++++++++++++++ quickdialog/QSortingSection.m | 2 +- quickdialog/QuickDialog.h | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 quickdialog/NSMutableArray+MoveObject.h create mode 100644 quickdialog/NSMutableArray+MoveObject.m diff --git a/QuickDialog.xcodeproj/project.pbxproj b/QuickDialog.xcodeproj/project.pbxproj index 00c6bbd0..8871daee 100644 --- a/QuickDialog.xcodeproj/project.pbxproj +++ b/QuickDialog.xcodeproj/project.pbxproj @@ -129,6 +129,8 @@ D8F180E813F0599A009B0CC2 /* QDynamicDataSection.h in Headers */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CC1 /* QDynamicDataSection.h */; }; D8F180E813F0599A009B0CC4 /* QTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CC3 /* QTableViewCell.m */; }; D8F180E813F0599A009B0CC6 /* QTableViewCell.h in Headers */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CC5 /* QTableViewCell.h */; }; + D8F180E813F0599A009B0CC8 /* NSMutableArray+MoveObject.m in Sources */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CC7 /* NSMutableArray+MoveObject.m */; }; + D8F180E813F0599A009B0CCA /* NSMutableArray+MoveObject.h in Headers */ = {isa = PBXBuildFile; fileRef = D8F180E813F0599A009B0CC9 /* NSMutableArray+MoveObject.h */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -277,6 +279,8 @@ D8F180E813F0599A009B0CC1 /* QDynamicDataSection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QDynamicDataSection.h; path = quickdialog/QDynamicDataSection.h; sourceTree = SOURCE_ROOT; }; D8F180E813F0599A009B0CC3 /* QTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = QTableViewCell.m; path = quickdialog/QTableViewCell.m; sourceTree = SOURCE_ROOT; }; D8F180E813F0599A009B0CC5 /* QTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QTableViewCell.h; path = quickdialog/QTableViewCell.h; sourceTree = SOURCE_ROOT; }; + D8F180E813F0599A009B0CC7 /* NSMutableArray+MoveObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSMutableArray+MoveObject.m"; path = "quickdialog/NSMutableArray+MoveObject.m"; sourceTree = SOURCE_ROOT; }; + D8F180E813F0599A009B0CC9 /* NSMutableArray+MoveObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSMutableArray+MoveObject.h"; path = "quickdialog/NSMutableArray+MoveObject.h"; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -416,6 +420,8 @@ D860356713E0534000CB1785 /* quickdialog */ = { isa = PBXGroup; children = ( + D8F180E813F0599A009B0CC9 /* NSMutableArray+MoveObject.h */, + D8F180E813F0599A009B0CC7 /* NSMutableArray+MoveObject.m */, D87B4FC314F16197006DA833 /* DOAutocompleteTextField.h */, D87B4FC414F16197006DA833 /* DOAutocompleteTextField.m */, D87B4FC514F16197006DA833 /* QAutoEntryElement.h */, @@ -530,6 +536,7 @@ buildActionMask = 2147483647; files = ( 2C54239F145ADF2B0026A152 /* QuickDialog.h in Headers */, + D8F180E813F0599A009B0CCA /* NSMutableArray+MoveObject.h in Headers */, D81F2ED714BBAFCE0066C372 /* QRootBuilder.h in Headers */, D81F2ED814BBAFCE0066C372 /* QBindingEvaluator.h in Headers */, D81F2EE714BBAFCE0066C372 /* QLabelElement.h in Headers */, @@ -718,6 +725,7 @@ 194C3FC814EDF1350036C9E7 /* NSMutableArray+IMSExtensions.m in Sources */, D87B4FCC14F16197006DA833 /* QAutoEntryElement.m in Sources */, D87B4FCE14F16197006DA833 /* QAutoEntryTableViewCell.m in Sources */, + D8F180E813F0599A009B0CC8 /* NSMutableArray+MoveObject.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/quickdialog/NSMutableArray+MoveObject.h b/quickdialog/NSMutableArray+MoveObject.h new file mode 100644 index 00000000..17cb1d1e --- /dev/null +++ b/quickdialog/NSMutableArray+MoveObject.h @@ -0,0 +1,7 @@ +#import + +@interface NSMutableArray (MoveObject) + +- (void)moveObjectFromIndex:(NSUInteger)from toIndex:(NSUInteger)to; + +@end \ No newline at end of file diff --git a/quickdialog/NSMutableArray+MoveObject.m b/quickdialog/NSMutableArray+MoveObject.m new file mode 100644 index 00000000..786fcb1f --- /dev/null +++ b/quickdialog/NSMutableArray+MoveObject.m @@ -0,0 +1,19 @@ +#import "NSMutableArray+MoveObject.h" + +@implementation NSMutableArray (MoveObject) + +- (void)moveObjectFromIndex:(NSUInteger)from toIndex:(NSUInteger)to +{ + if (to == from) + return; + + id objectToMove = [self objectAtIndex:from]; + [self removeObjectAtIndex:from]; + if (to >= [self count]) { + [self addObject:objectToMove]; + } else { + [self insertObject:objectToMove atIndex:to]; + } +} +@end + diff --git a/quickdialog/QSortingSection.m b/quickdialog/QSortingSection.m index 0d0e7589..f1553808 100644 --- a/quickdialog/QSortingSection.m +++ b/quickdialog/QSortingSection.m @@ -44,7 +44,7 @@ - (void)fetchValueIntoObject:(id)obj { } - (void)moveElementFromRow:(NSUInteger)from toRow:(NSUInteger)to { - [self.elements exchangeObjectAtIndex:from withObjectAtIndex:to]; + [self.elements moveObjectFromIndex:from toIndex:to]; } diff --git a/quickdialog/QuickDialog.h b/quickdialog/QuickDialog.h index f0454cb8..f4bbf5dd 100644 --- a/quickdialog/QuickDialog.h +++ b/quickdialog/QuickDialog.h @@ -15,6 +15,7 @@ #import "QuickDialogController.h" #import "QuickDialogController+Loading.h" +#import "NSMutableArray+MoveObject.h" #import "QuickDialogTableView.h" #import "QuickDialogTableDelegate.h"