gpt4 book ai didi

ios - xcode 搜索栏崩溃尝试输入内容

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:21:56 25 4
gpt4 key购买 nike

enter image description here

#pragma Search Methods

-(void)filterContentForSearchText:(NSString *)searchText scope:(NSString *)scope
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",searchText];
_AramaSonuclari = [_TarifAdi filteredArrayUsingPredicate:predicate];

}

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

// Return the number of rows in the section.
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return [_AramaSonuclari count];
}
else
{
return _TarifAdi.count;
}

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];

cell.tag = indexPath.row;
//cell.imageView.image = nil;

if (tableView == self.searchDisplayController.searchResultsTableView)
{
cell.TitleLabel.text = _AramaSonuclari[indexPath.row];
}
else
{
cell.TitleLabel.text = _TarifAdi[indexPath.row];
}

return cell;
}

我们的问题是,当我们尝试在搜索栏中输入任何字符时,应用程序崩溃,我们确实调试了我们的代码,没有错误。我们认为,我们的问题出在 Storyboard连接上;我还添加了一张图片。当我们删除 searchBar 引用导出时,我们可以输入一些东西,但当然代码在没有连接的情况下无法工作。

错误日志:

2014-07-14 13:29:08.577 SevgiLezzeti[3839:60b] *** Assertion failure in -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:5439

2014-07-14 13:29:08.582 SevgiLezzeti[3839:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier TableViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

最佳答案

您还必须将单元格注册到 searchdisplaycontroller。

Important: You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.

在 View 中加载

如果您在代码中创建单元格

 [self.searchDisplayController.searchResultsTableView registerClass:[TableViewCell class] 
forCellReuseIdentifier:@"IdentifierForCell"];

如果你在 nib 中创建单元格

  [self.searchDisplayController.searchResultsTableView registerNib:[UINib nibWithNibName:@"CellNibName" bundle:nil]
forCellWithReuseIdentifier:@"IdentifierForCell"];

关于ios - xcode 搜索栏崩溃尝试输入内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24734456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com