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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:36:27+00:00 2026-06-01T18:36:27+00:00

I have an array of custom objects called array which stores a bunch of

  • 0

I have an array of custom objects called array which stores a bunch of core data. I use this array to populate my UITableView and to create the cells. I then try to use the same array when UISearch is opened but at this point the array is empty, how could I retain the objects in the array?

EDIT

Ok, here is some of my code

my .h file

@interface SelectCourses : UIViewController <DataHandlerDelegate, UITableViewDataSource, UITableViewDelegate, UITableViewDataSource> {
DataHandler *dataHandler;
NSMutableArray *courses;
IBOutlet UITableView *table;
IBOutlet UISearchBar *searchFilter;
//NSMutableArray *filteredCourses;
BOOL isFiltered;
}

@property (retain) NSMutableArray* filteredCourses;

Then my .m file, I have left out several functions which I believe are irrelevant

@implementation SelectCourses

@synthesize Delegate;
@synthesize filteredCourses;
...
...

- (void) dataHandlerHasLoadedCourseData:(NSMutableArray *)courseData {
courses = courseData;
[table reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(isFiltered){
    return filteredCourses.count;
}
if (courses) {
    NSLog(@"Count: %i", [courses count]);
    if (courses.count == 1) {
        return 0;
    }
    return [courses count];
}
else
    return 0;
}
...
...
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchFiltert { 
NSLog(@"searchBarSearchButtonClicked");//More debugging

if(searchFilter.text.length == 0)
{
    isFiltered = FALSE;
}
else
{
    NSLog(@"%@", [NSString stringWithFormat:searchFilter.text]);
    isFiltered = true;


    for (Course *course in courses) 
    {
        NSRange codeRange = [course.Code rangeOfString:searchFilter.text options:NSCaseInsensitiveSearch];
        NSRange nameRange = [course.Name rangeOfString:searchFilter.text options:NSCaseInsensitiveSearch];
        if(codeRange.location != NSNotFound || nameRange.location != NSNotFound)
        {
            [filteredCourses addObject:course];
        }
    }
}
[table reloadData];
}

I still get the following error when running the script, I simply assumed it was due to the array being empty

2012-04-11 20:54:23.067 scheduleTable[45885:fb03] -[__NSArrayM Code]: unrecognized selector sent to instance 0x897b360
2012-04-11 20:54:23.068 scheduleTable[45885:fb03] *** WebKit discarded an uncaught exception in the webView:shouldInsertText:replacingDOMRange:givenAction: delegate: <NSInvalidArgumentException>     -[__NSArrayM Code]: unrecognized selector sent to instance 0x897b360

My course.h and .m looks like this

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>

@class Post;

@interface Course : NSManagedObject

@property (nonatomic, retain) NSString *Code;
@property (nonatomic, retain) NSString *Name;
@end

and

#import "Course.h"
#import "Post.h"

@implementation Course

@synthesize Code;
@synthesize Name;
@end
  • 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-01T18:36:29+00:00Added an answer on June 1, 2026 at 6:36 pm

    I tried using the retain method as Oral b answered but it got me nowhere, I am a bit of a newbie to Objective c which is why I am having the issues.

    My courses array was declared in an interface and I was not able to achieve the same result with it as I did with the new array I created just for the search. So in ViewDidLoad I do this

    coursesForSearch = [[NSMutableArray alloc] init];
    

    Then where objects were added to my other array I simply added this array and also added the objects to it.

    Now I can get objects from the array like so

    [[coursesForSearch objectAtIndex:500] objectAtIndex:0]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of custom objects. MyCustomArr[]. I want to convert this to
I have a custom made class called Graph in which I use adjacency lists.
I have a general (custom) jQuery plugin. $.fn.something(). This gets called on some objects
I have a custom object that contains an array (called children) where objects of
I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit
I have a method that is adding custom objects to an array in a
I have a listview connected to a custom array adapter. This list shows information
I have a class called XYZ inheriting from NSObject and an array which contains
I have a NSTreeController which array is bound to a items (custom) property of
I have the following setup using Core Data: Nib1: A WindowController with two custom

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.