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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:10:53+00:00 2026-06-11T15:10:53+00:00

so first I’ll give some background information so you can understand my problem completely.

  • 0

so first I’ll give some background information so you can understand my problem completely. I’ve spent hours looking for a solution but still can’t seem to get it right. So I’m trying to create an app that loads a tableView as a subview on a uiviewcontroller (SubviewPracticeMasterViewController). The table view is subclassed on another uiviewcontroller(SubviewPracticeViewController), and is loaded as a uiview on SubviewPracticeMasterViewController.

I also have an NSObject called LeadsInformation. LeadsInformation.h looks like this

#import <Foundation/Foundation.h>

@interface LeadsInformation : NSObject

@property (nonatomic, copy)NSString *leadName;
@property (nonatomic, copy)NSString *lastName;
@property (nonatomic, copy)NSString *firstName;
@property (nonatomic, copy)NSString *areaCode;
@property (nonatomic, copy)NSString *phoneNumber;
@property (nonatomic, copy)NSString *status;
@property (nonatomic, copy)NSString *notes;


-(id)initWithName: (NSString *)leadName lastName: (NSString *)lastName firstName:      (NSString *)firstName
     areaCode: (NSString *)areaCode phoneNumber: (NSString *)phoneNumber status: (NSString *)status 
        notes: (NSString *)notes;

@end

So on SubviewPracticeViewController.m, I programmatically add 4 LeadsInformation objects into an array called ‘dataArray’ and load specific string values into a custom cell in my cellForRowAtIndexPath method.

Now this is where my problem is occurring. I am also loading a custom header from a xib file. The header has two buttons on it: I want the first button to sort the cells alphabetically based on the first column, and I want the second button to sort the cells alphabetically based on the second column of the cell.

The table view is showing exactly as I want it to, with the custom table header as well, and the buttons are being clicked. However, the cells are not getting sorted. I have put the code for sorting by the first column in the IBAction method associated with its button on the header. Here is the code:

- (IBAction)sortLeadName:(id)sender {
    NSSortDescriptor *leadNameDescriptor = [[NSSortDescriptor alloc] initWithKey:    @"leadName" ascending:YES selector:@selector(localizedStandardCompare:)];
    NSArray *sortDescriptor = [NSArray arrayWithObject:leadNameDescriptor];
    NSArray *sortedArray = [self.dataArray sortedArrayUsingDescriptors:sortDescriptor];

    self.dataArray = [[NSMutableArray alloc] initWithArray:sortedArray];
    [[self tableView] reloadData];

}

And here is the code for cellForRowAtIndexPath just in case:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"Identifier"];
    if (cell == nil) {

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }

    LeadsInformation *leadAtIndex = [self.dataArray objectAtIndex: indexPath.row];

    UILabel *label;
    label = (UILabel *)[cell viewWithTag:1];
    label.text = leadAtIndex.leadName;

    label = (UILabel *)[cell viewWithTag:2];
    label.text = leadAtIndex.status;

    return cell;
}

Any help would be greatly appreciated. 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-06-11T15:10:54+00:00Added an answer on June 11, 2026 at 3:10 pm

    So it turns out I was doing some unnecessary work that was throwing me off. I didn’t need to sort a copy of my array and then reload my dataArray as the new sorted copy. I just needed to directly sort the array with the SortDescriptor, like so:

    -(IBAction)sortLeadName:(id)sender {
        NSSortDescriptor *sortDescript = [[NSSortDescriptor alloc] initWithKey:@"status"  ascending: YES selector:@selector(localizedStandardCompare:)];
    
        [self.dataArray sortUsingDescriptors: [NSArray arrayWithObject: sortDescript]];
        [self.tableView reloadData];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first off I'm a noob to PHP but here is my problem. I am
I have a jquery bug and I've been looking for hours now, I can't
First of all, some background: I'm trying to get in a list of integers
First of all i give you a short example for my problem. Keep in
First off...here's the problem... Give an example of a directed graph G = (V,
first of all some details: I configured security as below in web.xml view plaincopy
First, some context: I'm a Python developer who has written a medium-sized application using
first sorry if its a stupid question but im lost a bit. So when
First time posting here, will try to be succinct. This is a classic 'can't
first question asked, so I'll get straight to it. I've got some C code

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.