相关疑难解决方法(0)

UIViewController不保留其以编程方式创建的UISearchDisplayController

在有关属性1UIViewController 文档中,它说:searchDisplayController

如果以编程方式创建搜索显示控制器,则在初始化时,搜索显示控制器会自动设置此属性.

当我这样创建我的UISearchDisplayController时:

[[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self] autorelease];
Run Code Online (Sandbox Code Playgroud)

-[UIViewController searchDisplayController]不是nil.但是,它在事件循环结束后被填写,这会导致搜索显示控制器在我触摸搜索栏时不显示.什么都没有崩溃.这很奇怪.如果我省略了呼叫autorelease,一切正常:

[[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
Run Code Online (Sandbox Code Playgroud)

然而,泄漏UISearchDisplayController(我用仪器验证了这一点).由于该searchDisplayController 属性被标记为(nonatomic, retain, readonly)我希望UISearchDisplayController它在设置后保留它.

此stackoverflow文章是相关的.

uiviewcontroller uisearchdisplaycontroller ios automatic-ref-counting

30
推荐指数
1
解决办法
6303
查看次数

在表视图中搜索栏和搜索显示控制器

我试图实现一个搜索栏,但我没有运气处理这个问题.我真的很感激可以提供任何帮助.我有一个大项目,我有一个表视图,我想在它上面实现一个搜索栏,看看实时过滤.我不使用Storyboard但我使用的是XIB.我添加了以下协议:

<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchDisplayDelegate>
Run Code Online (Sandbox Code Playgroud)

我在@interface中声明了2个数组,第一个用于整个元素,第二个用于过滤的数组:

    NSArray*     OldList;
    NSArray*     filteredList;
Run Code Online (Sandbox Code Playgroud)

然后我设置了行数和节数,然后:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    myClassCell *cell = [tableView dequeueReusableCellWithIdentifier:MYCELLCLASS];
    if (cell == nil)
    {
        cell = [myClassCell newFromNib];
    }
    NSMutableDictionary* elem = nil;
    if (tableView == self.searchDisplayController.searchResultsTableView)
    {
        elem = [filteredList objectAtIndex:indexPath.row];
        if ([elem count]+1 > indexPath.row)
            [cell showValues:elem];
        else
            [cell showValues:nil];
    }
    else
    {
        elem = [OldList objectAtIndex:indexPath.row];
        if ([elem count]+1 > indexPath.row) 
            [cell showValues:elem];
        else
            [cell showValues:nil];
    }
    return cell;
}

-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate = …
Run Code Online (Sandbox Code Playgroud)

uitableview uisearchbar uisearchdisplaycontroller ios

1
推荐指数
1
解决办法
2万
查看次数