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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:37:29+00:00 2026-05-26T16:37:29+00:00

I have an action for searching in NSMutableArray with name searcharray, which is equal

  • 0

I have an action for searching in NSMutableArray with name searcharray, which is equal to array with which NSTableView are connected.And I wrote a method for adding items to TableView just by sending NSMutableArray to my method.
The problem is that after searching if I delete what I have typed in SearchField and SearchField is empty, the compiler doesn’t feel that it’s empty and my TableView getting empty too, but due my code it’s have to be with data from searcharray.
Here is my code:

#import "myTableViewAppDelegate.h"

@implementation myTableViewAppDelegate

@synthesize window;
@synthesize searcharray;


-(void)addItems:(NSMutableArray *)ar{
    array = ar;
    [array retain];
    [tableView reloadData];
}
- (int)numberOfRowsInTableView:(NSTableView *)tableView{
    return (int)[array count];
}
- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn:(NSTableColumn *)tableColumn
            row:(int)row
{
    return [array objectAtIndex:row];
}



- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    NSMutableArray *animals = [[NSMutableArray arrayWithObjects:@"Cat", @"Dog", @"Fish", @"Squirrel", @"Bear", @"Turtle", nil] retain];
    NSLog(@"%@",animals);
    searcharray = animals;
    [self addItems:animals];

}

- (IBAction)search:(id)sender {
    //NSLog(@"%@",searcharray);
    NSString *filter = [[NSString alloc] initWithString:[search stringValue]];
    NSMutableArray *result = [[NSMutableArray alloc] init];
    if (filter != nil) {
      for (NSString *item in searcharray) {
        if ([item rangeOfString:[search stringValue]].location !=NSNotFound ) {
            NSLog(@"Item %@ contains %@",item,[search stringValue]);
            [result addObject:item];
        }
    }  
    }
    else{
    result = searcharray;
    }
    NSLog(@"%@",result);
    [self addItems:result];
    [result release];
    [filter release];
}
@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-05-26T16:37:30+00:00Added an answer on May 26, 2026 at 4:37 pm

    Fixed it.

    if (filter != nil || filter.length != 0)
    

    I don’t know why, but just checking variable equal to NULL wasn’t enough….

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

Sidebar

Related Questions

I have an action which I need to post forward onto another action if
I have an action method that depending on some conditions needs to return a
I have a action on my controller (controller name is 'makemagic') called 'dosomething' that
I have an action that relies on User.Identity.Name to get the username of the
I have an action method that takes in two different objects. I am posting
Hey, I have been searching all over for a solution to injecting into action
I Have a Strongly typed user control which i use for Searching a certain
I have a page which is used for searching through listings by submitting data
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
I have an action handling a form post, but I want to make sure

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.