【问题标题】:Help With UISearchBar Methods帮助 UISearchBar 方法
【发布时间】:2009-11-15 00:41:02
【问题描述】:

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

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

我应该添加什么对象才能让它工作。

这是我的代码:

{
[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 总是显示正确的过滤项。

【问题讨论】:

    标签: iphone search uitableview uisearchbar


    【解决方案1】:

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

    【讨论】:

    • 哇。我错过了示例中的一行代码。 self.filteredListContent = [NSMutableArray arrayWithCapacity:[self.tableDataSource count]];非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多