I have a situation here, I have two arrays,array1 and array2 and one tableview. I have loaded array1 to the table view. So here, I’m sorting array2, I’ve done that, but how can I sort array1 with respect to the change in array2 and to reload array1 in tableview. That is I need to sort array1 automatically when I sort array2.
Any ideas? Please share your thoughts.
Thanks 🙂
I have a situation here, I have two arrays,array1 and array2 and one tableview.
Share
The logical advice, would be that, if the objects are sorted together, then they’re related somehow, and both pieces of data should conform a new object (A dictionary, an NSObject, whatever).
I mean, if array1 is
[1, 5, 4, 3, 2]and array2 is["hello", "world", "big", "little", "my"], then the mixed array would be:[(1, "hello"), (5, "world"), (4, "big"), (3, "little"), (2, "my")].Sorting this is trivial, and it makes sense if the data is correlated (no way to tell since you didn’t specify this).
Objective-C example
Custom Object (CustomObject.h) that holds both name/number (using a number as a trivial example):
CustomObject.m:
Using these objects together with sorting:
The output looks like: