我有一个UIViewController与标准的UITableView和搜索栏添加了搜索委托.视图在导航栏中有一个分段控件,当用户更改分段控件时我想隐藏searchBar.
我使用的代码是:
- (void)segChange {
if ([segmentedControl selectedSegmentIndex] == 0) {
[[[self searchDisplayController] searchBar] setHidden:YES];
// This does not work:
[[[self searchDisplayController] searchResultsTableView] setContentOffset:CGPointZero animated:NO];
}
else {
[[[self searchDisplayController] searchBar] setHidden:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
代码隐藏了searchBar,但它在表格视图的顶部留下了一个令人讨厌的空白区域....任何关于如何摆脱它的想法?
谢谢
iphone uitableview uisegmentedcontrol uisearchbar uisearchdisplaycontroller
我使用UISearchDisplayController和UITableView实现了一个SearchBar来显示搜索结果.我使用libxml2和xpath来解析HTML网站并搜索源代码中所需的内容.由于我是ObjC的新手,我使用Apple提供的示例项目TableSearch作为搜索和显示部分作为开始.一切正常,我可以解析网站上的特定内容,并将它们正确地组合在网站上,并将它们显示在不同的TableView行视图中.我想使用用户输入来搜索特定的网站.我只有以下问题:
如果您查看项目TableSearch(类MainViewController.m),您会注意到它更新了"filteredListContent"并重新加载TableView,并在用户输入时自动显示它:
[...]
#pragma mark -
#pragma mark Content Filtering
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
/*
Update the filtered array based on the search text and scope.
*/
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
/*
Search the main list for products whose type matches the scope (if selected) and whose name matches searchText; add items that match to the filtered array.
*/
for (Product *product in listContent)
{
if ([scope isEqualToString:@"All"] || [product.type isEqualToString:scope])
{
NSComparisonResult result …Run Code Online (Sandbox Code Playgroud) 在MonoTouch模拟器中,我通过以下诊断获得随机崩溃:
/tmp/mono-gdb-commands.FV1b8V:1: Error in sourced command file:
unable to debug self
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Run Code Online (Sandbox Code Playgroud)
跟踪提到"UISearchDisplayController dealloc":
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging.void_objc_msgSend (intptr,intptr) <IL 0x00024, 0xffffffff>
at MonoTouch.Foundation.NSObject/MonoTouch_Disposer.Drain (MonoTouch.Foundation.NSObject) [0x0002a] in /Users/plasma/Source/iphone/monotouch/Foundation/NSObject.cs:305
at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00052, 0xffffffff>
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26
at TestCase.Application.Main (string[]) [0x00000] …Run Code Online (Sandbox Code Playgroud) crash uinavigationcontroller uisearchbar xamarin.ios uisearchdisplaycontroller
I have a IUSearchBar with an UISearchDisplayController, and everything is working well:
screenshot 1 http://joeranbosma.nl/xcode/sdc1.png
screenshot 1 http://joeranbosma.nl/xcode/sdc2.png
iphone objective-c uisearchbar uisearchdisplaycontroller ios
在我的主tableView中,我有一些自定义单元格(基本上是带有imageView的单元格).
仅当我的plist上的值为false时才设置imageView.然后,当它为真时,imageView为零.
基本上当用户输入detailView时,该值设置为YES和cell.imageViewnil.
它没关系,它有效
我正在使用a searchDisplayController,当我搜索具有cell.imageView的东西时,进入detailView然后返回到searchResultsTable,单元格仍然是图像,而它不应该,但主tableView具有正确的单元格(所以,没有图像).
我认为它可能依赖于searchResultsTableView,但我不确定.我试过了
[self.searchDisplayController.searchResultsTableView reloadData];
Run Code Online (Sandbox Code Playgroud)
没有效果.
我怎么能重新加载searchResultsTableView,以便它显示正确的单元格,那些带有图像的那些以及那些没有图像的单元格?
任何帮助赞赏!
编辑
这是我的cellForRowAtIndexPath方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *rows;
if (tableView == self.searchDisplayController.searchResultsTableView) {
rows = filteredList; //for search
} else {
NSDictionary *section = [localSortedTips objectAtIndex:indexPath.section];
rows = [section objectForKey:@"Rows"];
}
NSDictionary *item …Run Code Online (Sandbox Code Playgroud) 我正在创建一个搜索控制器,我想做自动完成.
没关系.
但是我从几个来源获得数据.首先,我从本地缓存中获取数据.然后我从网上加载数据.
因此,当我们完成下载数据时,我们希望让searchcontroller重新加载包含新数据的表.
我们怎么做?
我试图实现一个搜索栏,但我没有运气处理这个问题.我真的很感激可以提供任何帮助.我有一个大项目,我有一个表视图,我想在它上面实现一个搜索栏,看看实时过滤.我不使用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) 如果我添加UISearchBar而不将其引用到UISearchDisplayController,则我的tintColor将正确显示。

searchBar.barTintColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];
Run Code Online (Sandbox Code Playgroud)
但是,如果我将我的UISearchBar引用到UISearchDisplayController,则颜色似乎有所不同...

searchBar = [[UISearchBar alloc] init];
[searchBar setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
searchBar.delegate = self;
searchBar.searchBarStyle = UISearchBarStyleProminent;
searchBar.placeholder = @"Buscar restaurantes o platillos";
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
self.tableView.tableHeaderView = searchBar;
Run Code Online (Sandbox Code Playgroud)
我在AppDelegate上的tintColor设置是
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UIToolbar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
self.window.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.backgroundColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f …Run Code Online (Sandbox Code Playgroud) 如何以编程方式显示/隐藏UISearchDisplayController中的这个不透明视图?

可能在searchDisplayControllerWillBeginSearch或searchDisplayControllerDidBeginSearch我需要设置一些东西......但是什么?
谢谢.
iphone objective-c uisearchbar uisearchdisplaycontroller ipad
我在一个相当标准的tableview上实现了一个UISearchDisplayController(表+搜索的数据源相同).我遇到的问题是当结果没有填满屏幕时,实际结果下面有"伪"行.
我能够设置背景颜色,但无法找到抑制这些行/分隔符的好方法.它们似乎与我的numberOfRowsInSection:委托响应分离.
如果我设置searchResultsTableView.separatorColor(绿色),它只会更改实际结果行.
我能够将separatorStyle更改为UITableViewCellSeparatorNone,但后来我必须在实际结果上手动重新创建分隔符,并且有边缘情况(如选择颜色覆盖我的视图).
是否有一种干净的方法来隐藏附加截图中指出的行?

当我开始在SearchBar中键入搜索文本时,我收到以下错误
Assertion failure in -[UISearchResultsTableView _configureCellForDisplay:forIndexPath:]
Run Code Online (Sandbox Code Playgroud)
我的cellForRowAtIndexPath代码Search Display Controller如下:
if(tableView == self.searchDisplayController.searchResultsTableView)
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
cell.textLabel.text = [search objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud) uisearchbar ×7
ios ×6
objective-c ×5
iphone ×4
uitableview ×4
cocoa-touch ×2
crash ×1
ipad ×1
xamarin.ios ×1
xcode ×1