Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:54:34+00:00 2026-05-28T19:54:34+00:00

I have 5 NSMutableArrays in cell. I need to sort cells by one value.

  • 0

enter image description here

I have 5 NSMutableArrays in cell. I need to sort cells by one value.
Example I need to sort cell by time.

[MyArray1 sortUsingSelector:@selector(compare:)];

but how I will be with other 4 NSMutableArray in cell?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:54:35+00:00Added an answer on May 28, 2026 at 7:54 pm

    It’s not a good idea to store data for your cells in 5 arrays, don’t separate them; create a data container class, store all values for each cell inside one data container object and then you can sort your array with data containers by one of the values.

    e.g.:

    DataContainer.h:

    @interface DataContainer : NSObject
    {
        NSDate *date1;
        NSDate *date2;
        NSString *upperTitle;
        NSString *mainTitle;
        NSString *subtitle;
    }
    
    @property (nonatomic, strong) NSDate *date1;
    @property (nonatomic, strong) NSDate *date2;
    @property (nonatomic, strong) NSString *upperTitle;
    @property (nonatomic, strong) NSString *mainTitle;
    @property (nonatomic, strong) NSString *subtitle;
    
    @end
    

    DataContainer.m:

    @implementation DataContainer
    @synthesize date1, date2, upperTitle, mainTitle, subtitle;
    @end
    

    Then you can create your DataContainer‘s (one for each cell) and store them in one NSMutableArray.

    e.g.:

    DataContainer *container = [[DataContainer alloc] init];
    [container setDate1:[NSDate date]];
    [container setMainTitle:@"blahblah"];
    ///...
    [cellArr addObject:container];
    

    To sort this array, use:

    cellArr = [cellArr sortedArrayUsingComparator:^(id cont1, id cont2) {
                    return [[(DataContainer *) cont1 date1] compare:[(DataContainer *) cont2 date1]];
                }];
    

    and then use them in your cellForRowAtIndexPath:

    DataContainer *container = [cellArr objectAtIndex:indexPath.row];
    //container.date1, container.date2, container.upperTitle, container.mainTitle and container.subtitle are the values that you need for your cell.
    

    Notice that this code is suitable if you’re using ARC (Automatic Reference Counting) for your project; if you’re not using ARC, then you need to change strong to retain in property definitions and add release‘s to needed places to avoid memory leaks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an UIPickerView with 3 components populated with 2 NSMutableArrays (2 components have
I have a NSMutableArray that I need to search for a string and return
I have a JSON file, and i need to extract values from it and
i have a UItableView and i have two buttons on each cell. You can
Hi I have a table view, and when I delete a cell I am
I have a NSMutableArray of QuoteMap objects. When I add one using the below
I have UItableview where every cell containing 5 cell and these cell are representing
I need to add 'ADD NEW ROW' cell to the table. And I add
I have successfully loaded the muscleName items into a table view but am not
i have a very simple table with only one row that has a uiswitch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.