I have a simple NSArray which has some arrays as objects which has some dates and strings as objects:
- NSArray (main array) —————> table view
- NSArray (secondary array)—> table view cell
- NSDate ——————–> table view cell text label
- NSString ——————-> table view cell detail text label
- etc.
- NSArray (secondary array)—> table view cell
I use the main array for my table view -> each cell got it’s own ‘secondary array’.
Now I want to sort the main array by the NSDate object. It sounds very easy but I have found no solution on the web for it.
I thought about using NSSortDesriptors but those just sort the array by the objects in the main array and not in the secondary array.
Hopefully you can help me
EDIT: Would it fix the problem if I use a NSDictionary as the secondary array?
You should be able to use NSArray sortedArrayUsingComparator if your app is targeted for iOS 4.0 or later:
This assumes that the date field is always in index 0 of the internal array. It would probably be a bit cleaner if you used a dictionary and keyed the date field by name, but if you are comfortable with the date field always remaining in index 0 then the above should work.