views:

104

answers:

1

So I'm having trouble implementing a search bar in my app.

The methods find the filtered items but for some reason they won't show up in my tableview. I think it has something to do with adding the objects to the filteredListContentArray.

What object should I be adding for this to work.

Here's my code:

{
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
for (NSDictionary *dictionary in tableDataSource) 
{

 NSString *testString = [dictionary valueForKey:@"Title"];
 NSLog(@"String list to be Searched is %@", testString);
 //NSLog(@"Contents of list are %@", testString);
 NSComparisonResult result = [testString compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
 //NSObject *filteredObject = [dictionary objectForKey:@"Title"];
 if (result == NSOrderedSame)

 {
  NSLog(@":-)");
  NSLog(@"Resulted object is %@", [dictionary valueForKey:@"Title"]);
  [self.filteredListContent addObject:dictionary];
 }
 else
 {
  NSLog(@":-(");
 }
}


NSLog(@"Contents of Filtered list are %@", self.filteredListContent);}

That last NSLog reads (null) every time, but the NSLog Above it always shows the correct filtered items.

A: 

where do you allocate memory for your filteredListContent? and there is tableDataSource array. do you fill your table from filteredListContent or from tableFataSource array? also you can try to print to console [filteredListContent description];

Morion
Wow. I missed one line of code from the sample.self.filteredListContent = [NSMutableArray arrayWithCapacity:[self.tableDataSource count]];Thanks so much!
monotreme