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 6602263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:51:21+00:00 2026-05-25T18:51:21+00:00

I have a situation here, I have two arrays,array1 and array2 and one tableview.

  • 0

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 🙂

  • 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-25T18:51:21+00:00Added an answer on May 25, 2026 at 6:51 pm

    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):

    @interface CustomObject : NSObject
    
    @property (nonatomic,retain) NSString *name;
    @property (nonatomic,assign) NSInteger number;
    
    + (id)customObjectWithName:(NSString*)name andNumber:(NSInteger)number;
    
    @end
    

    CustomObject.m:

    #import "CustomObject.h"
    
    @implementation CustomObject
    
    @synthesize name, number;
    
    + (id)customObjectWithName:(NSString*)name andNumber:(NSInteger)number
    {
        CustomObject *customObject = [[CustomObject alloc] init];
    
        customObject.name = name;
        customObject.number = number;
    
        return customObject;
    }
    
    - (NSString *)description
    {
        return [NSString stringWithFormat:@"(Number:%d, Name:%@)", self.number, self.name];
    }
    
    - (void)dealloc
    {
        [name release];
        [super dealloc];
    }
    
    @end
    

    Using these objects together with sorting:

    NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
                                [CustomObject customObjectWithName:@"Hello" andNumber:1], 
                                [CustomObject customObjectWithName:@"gentlemen?" andNumber:5], 
                                [CustomObject customObjectWithName:@"you" andNumber:4],
                                [CustomObject customObjectWithName:@"are" andNumber:3], 
                                [CustomObject customObjectWithName:@"how" andNumber:2],
                                    nil];
    
    [array sortUsingComparator:^NSComparisonResult(id obj1, id obj2)
    {
        return [(CustomObject*)obj1 number] - [(CustomObject*)obj2 number];
    }];
    
    NSLog(@"Results: %@", array);
    

    The output looks like:

    2011-09-23 03:27:14.388 Test[5942:b303] Results: (
    "(Number:1, Name:Hello)",
    "(Number:2, Name:how)",
    "(Number:3, Name:are)",
    "(Number:4, Name:you)",
    "(Number:5, Name:gentlemen?)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation: I have one table that contains a list of drugs
Here's the situation: We have some generic graphics code that we use for one
Here is my situation - I have two nested view models: <%=Html.EditorFor(x => x.DisplayEntitiesWithRadioboxesViewModel)%><br
I have a situation where I have two arrays and I use one array(A)
Here is my situation: I have an application that use a configuration file. The
Okay, here's the situation. I have two NSManagedObjects called Store and Aisle . There
Alright here's the situation, I have an application written in the Zend_Framework, that is
Here's the situation: I have two DateTimePicker controls for the start date and end
I have a bizarre situation with two bzr branches. The two branches differ one
I have a situation that i have a hidden div with two input elements

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.