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

The Archive Base Latest Questions

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

I simply want to sort an NSArray by the index number i.e. The order

  • 0

I simply want to sort an NSArray by the index number i.e. The order in which the values are entered into the array.

My problem is that I use this array in a uipicker, and therefore when reusing labels, end up with my values in the wrong order

My values consist of fractions. 1/4,3/8,1/2,3/4,1,1-1/14,1-3/8 etc

I want these fractions to display in the order they are entered

Must be simple, but I am having no luck

When I use sorted array localisedstandardcompare all the values get out of sequence

Any help will be appreciated

  - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row    inComponent:(NSInteger)component
    {


    // Only calls the following code if component "0" has changed.
    if (component == 0) 
    {

        // Sets the global integer "component0Row" to the currently selected row of component "0"
        component0Row  = row;

        // Loads the new values for the selector into a new array in order to reload the data.
        NSDictionary *newDict = [[NSDictionary alloc]initWithDictionary:[pickerData objectForKey:[selectorKeysLetters objectAtIndex:component0Row]]];

        NSArray *sortArray = [[NSArray alloc]initWithArray:[newDict allKeys]];

        NSMutableArray *newValues = [[NSMutableArray alloc]initWithArray:[sortArray  sortedArrayUsingSelector:@selector(compare:)]];

        self.selectorKeysNumbers = newValues;

        component1Row = 0;
        [self.myPicker selectRow:0 inComponent:1 animated:NO];
  • 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-25T22:32:52+00:00Added an answer on May 25, 2026 at 10:32 pm

    Assuming that the array values are NSStrings the sort order will be by string value, not numeric value. In order to sort these fractions (rational numbers) you would have to write you own compare function.

    But see @hypercrypt, the array should already be in the order entries were made.

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

Sidebar

Related Questions

I simply want to show off a model in a table that is paginated
I have several sql queries that I simply want to fire at the database.
Hey guys I have an assigned array from mysql results and I simply want
I want to implement some sort of lookup table in C++ that will act
I have a small number of static sites where I simply want to hide
I'm trying to figure out how to sort a 2d array into a 3d
I want to query elements with order by name. If I simply write Element.all.order('name')
I simply want to open up the WPF Popup with a delay, sort of
Why would I want to use Oracle Designer as opposed to simply maintaining SQL
I have an array of structures and I want to sort them. I have

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.