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

  • Home
  • SEARCH
  • 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 7926761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:55:14+00:00 2026-06-03T18:55:14+00:00

I have an array which has 200 objects in it on page load i

  • 0

I have an array which has 200 objects in it on page load i copy these (mutable copy) to a temp array called filteredarray which i then display in a uitableview. This all works fine 🙂

i then have a segment selector which when selected is supposed to filter my orginal array using a predictate and filteredarray will now hole the contents of the objects which meet the predictate criteria again from what i can see this is working fine 🙂

i then try and reload my table view ( again with filteredarray ) which when i step through seems to work ok for the first couple objects in filteredarray but then filteredarray seems to be “emptied” if thats the right word, and my code crashes just after the table has started to be refreshed. Im sure it must be a memory issue or something. im pretty new to objective c so any help would be much appreciated. i have listed some of my code below

- (void)viewDidLoad
{
[super viewDidLoad];    
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
filteredArray = [appDelegate.originalArray mutableCopy];    
}



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

static NSString *cellidentifier = @"customcell";
customcell *cell = (customcell *)[tableView dequeueReusableCellWithIdentifier:
                                  cellidentifier];
array_details *arrayObj = [filteredArray objectAtIndex:indexPath.row];

// UITableViewCell cell needs creating for this UITableView row.
if (cell == nil)
{
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customcell" owner:self options:nil];

    for (id currentObject in topLevelObjects) {
        if ([currentObject isKindOfClass:[customcell class]]) {
            cell = (customcell *) currentObject;
            break;
        }
    }
}


    cell.line1.text = arrayObj.line1;
    cell.line2.text = arrayObj.line2;
return cell;
}


-(IBAction)change_segment:(id)sender;{
if(segmentcontrol.selectedSegmentIndex == 2){
    filteredArray = [appDelegate.originalArray mutableCopy];      
    NSPredicate *testForTrue = [NSPredicate predicateWithFormat:@"selected == YES"];
    filteredArray = [filteredArray filteredArrayUsingPredicate:testForTrue]; 
}   

[my_table reloadData];  // its when i do this that the array filtered array seems to somehow get "emptied"

and my filteredarray is declared in my.h file as a nsmutable array

NSMutableArray *filteredArray;
  • 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-03T18:55:30+00:00Added an answer on June 3, 2026 at 6:55 pm

    Since you have a NSMutableArray, I would suggest using filterUsingPredicate: instead of filteredArrayUsingPredicate:. The filtered array you start with is retained because you obtain it via a copy but the one you replace it with in your change_segment: method isn’t.

    (I suspect this is the problem but details of the crash and its related exception would make diagnosis easier.)

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

Sidebar

Related Questions

I have an array which has the contents as the result of an sql
I have created 4 buttons via Interface Builder. I have an array which has
I have an int array which has no elements and I'm trying to check
I have an array Items which has 10 elements. I need to remove the
I have a C++ code which has 3 array declarations. float A[NUM]; float B[NUM];
I'm using ASP.NET MVC and have a model which has an image (byte array)
I have an array which i need to sort its elements by occurrence then
I have an array which contains around 50-200 hyperlinks. How can I pass this
I have a array of my object Country which has the attributes code and
Hi I have an array list which has some numbers in it like {23,16,45,26,2,5,9}

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.