Note that there are some explanatory texts on larger screens.

plurals
  1. PONSTableview and SearchField
    primarykey
    data
    text
    <p>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:</p> <pre><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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload