开发者

Help With UISearchBar Methods

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 a开发者_JS百科lways shows the correct filtered items.


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];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜