所以我无法在我的应用程序中实现搜索栏。
这些方法会找到过滤后的项目,但由于某种原因,它们不会出现在我的表格视图中。我认为这与将对象添加到过滤列表内容数组有关。
我应该添加什么对象才能使它起作用。
这是我的代码:
{
[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 总是显示正确的过滤项。