iOS   发布时间:2022-05-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – UISearchDisplayController和自定义单元格大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我在UITableViewController中实现了一个UISearchDisplayController.搜索工作正常,但UISearhDisplayController创建一个带有标准单元格的新tableView,而我的tableView正在使用自定义单元格.另一个问题是我使用了一个segue: - (void)prepareForSegue:(UIStoryboardSegue *)seg
@H_772_6@
@H_772_6@
我在UITableViewController中实现了一个UISearchDisplayController.搜索工作正常,但UISearhDisplayController创建一个带有标准单元格的新tableView,而我的tableView正在使用自定义单元格.另一个问题是我使用了一个segue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

而且searchResultsTableView中的单元格没有触发segue ..

如何使用自定义单元格和segue工作显示搜索结果

这是代码

...

- (NSInteger)tableView:(UITableView *)tableView @R_675_10793@erOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView){ 
return [nameFilteredObj count];
} else {
return [sortedObj count];
}}

- (Customcatell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"customcatell";

Customcatell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[Customcatell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:CellIdentifier];
}
if (tableView == self.searchDisplayController.searchResultsTableView)
{
cell.textLabel.text = [[sortedObj objectATindex:indexPath.row] valueForKey:@"Name"];
 } else {
cell.nameLabel.text = [[sortedObj objectATindex:indexPath.row] valueForKey:@"Name"];
cell.countryLabel.text = [[sortedObj objectATindex:indexPath.row] valueForKey:@"Country"];
cell.bottleImageView.image = [UIImage imagenamed:[[sortedObj objectATindex:indexPath.row] valueForKey:@"Image"]];
} 
return cell; 
}

//The codes for filtering the results and update of searchResultsTableView (not necessary for this question I think):

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
[nameFilteredObj removeAllObjects];

for(NSDictionary *obj in sortedObj)
{
NSString *objName = [obj objectForKey:@"Name"];
NSRange range = [objName rangeOfString:searchText options:NSCaseInsensitiveSearch];
if (range.LOCATIOn != NsnotFound) {
    [nameFilteredObj addObject:obj];
}}}

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

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
[self filterContentForSearchText:[self.searchDisplayController.searchbar text] scope:
 [[self.searchDisplayController.searchBar scopeButtontitles] objectATindex:searchOption]];
return NO;}
...

我正在使用Storyboard作为界面.

解决方法@H_772_36@ @H_675_37@ 实际上很容易做到,但我发现了许多复杂的半工作解决方案.使用这个简单的部分,SearchResultsTableView是GONE:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
...
self.searchDisplayController.searchResultsTableView.hidden=YES;
return YES;
}

大佬总结

以上是大佬教程为你收集整理的iphone – UISearchDisplayController和自定义单元格全部内容,希望文章能够帮你解决iphone – UISearchDisplayController和自定义单元格所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:iphone单元格自定义
猜你在找的iOS相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap