0

所以我无法在我的应用程序中实现搜索栏。

这些方法会找到过滤后的项目,但由于某种原因,它们不会出现在我的表格视图中。我认为这与将对象添加到过滤列表内容数组有关。

我应该添加什么对象才能使它起作用。

这是我的代码:

{
[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);}

最后一个 NSLog 每次都读取(null),但它上面的 NSLog 总是显示正确的过滤项。

4

1 回答 1

0

您在哪里为您的过滤列表内容分配内存?并且有 tableDataSource 数组。你是从filteredListContent 还是从tableFataSource 数组填充你的表?您也可以尝试打印到控制台 [filteredListContent 描述];

于 2009-11-15T00:51:19.117 回答