带有UIsearchBarController的ios7崩溃了吗? [英] ios7 with UIsearchBarController crashes?

查看:106
本文介绍了带有UIsearchBarController的ios7崩溃了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ios7。
在我的应用程序中,我有UITableView和UISearchBar控制器。实现UISearchBar控制器时
我的应用程序崩溃
由于以下原因:

I am woking on ios7. In My app i am having UITableView and UISearchBar Controller. while implementing UISearchBar Controller my application crashes DUE TO following reason:

由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因: '无法使用标识符listcell对单元格进行出列 - 必须为标识符注册一个nib或类或在故事板中连接原型单元格

我是使用自定义UITabelViewCell.UISearchBarController委托方法也已实现。

i am using custom UITabelViewCell.UISearchBarController delegate methods are also implemented.

任何人都可以为我提供更好的链接或解决方案吗?

Can any one provide me a better link or solution for this?

以下是我的代码:

// ----------------------代码搜索部分------------------

//----------------------code for search part------------------

-(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{ 
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF Contains[cd] %@",searchText];

    searchResults = [_detailList filteredArrayUsingPredicate:resultPredicate];
}


-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles]objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    return YES;
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.searchDisplayController.searchResultsTableView)
    {
        return [searchResults count];
    }
    else
    return _detailList.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"listcell";
//
   ListCell *listcell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


        listcell.lbl_detail.text = _detailList [indexPath.row];
    listcell.lbl_Address.text = _detailList1 [indexPath.row];
    listcell.lbl_link.text = _detailList2 [indexPath.row];
    listcell.lbl_number.text = _detailList3 [indexPath.row];


    return listcell;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
[(ContainerViewController *)self.parentViewController addDetailViewController];
}

谢谢

推荐答案

您应该在方法viewDidLoad中添加以下行:

You should put the following line in the method viewDidLoad:

[self.searchDisplayController.searchBar registerClass:[ListCell class] forCellReuseIdentifier: @listcell];

[self.searchDisplayController.searchBar registerClass:[ListCell class] forCellReuseIdentifier:@"listcell"];

这篇关于带有UIsearchBarController的ios7崩溃了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆