我想在用户点按搜索栏时,但在输入任何文本之前显示一些默认内容.
我有一个使用settext的解决方案:
- (void) searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
[searchDisplayController.searchBar setText:@" "];
}
Run Code Online (Sandbox Code Playgroud)
这有效,但它不优雅,搜索栏中的提示文字消失了.
有没有更好的方法将数据预加载到UISearchDisplayController中的SearchResultTableView,而无需在自定义控制器中自己实现整个UISearch功能?
有关所需效果的演示,请查看Safari的搜索框,如果点击它,搜索界面将打开,显示之前的搜索.
以下问题仅发生在iOS 7.0+设备上运行的iOS 6.0/6.1应用程序上.
所以我有一个UISearchDisplayController搜索我们的API并返回数据.这一切都有效,一切都按我们的意愿显示.我们所看到的唯一的问题是,内容填充后searchResultsTableView,却仿佛当键盘最初是隐藏的,在contentSize的searchResultsTableView比数据大得多,实际上似乎是键盘的尺寸.当我进入搜索栏,并显示键盘并再次点击"搜索"(只是为了隐藏键盘)时,contentSize然后正确调整以仅填充屏幕,仅此而已.下面是我与初始tableView人口谈论的屏幕截图.

白色是表格数据,灰色/奶油色是额外的tableView空间.
有想法该怎么解决这个吗?
uisearchdisplaycontroller ios uisearchresultscontroller ios6 ios7
我有一个应用程序,显示了相当多的数据UITableView.我已经在界面生成器中添加了UISearchBar和.但我不知道如何使用它.如果有人能为此提供快速解决方案,我将不胜感激.我只是要求它在您键入时工作,以在单元格(或从数组)中查找搜索查询的匹配项.UISearchDisplayControllerUITableViewUITableView
更新1:这是numberOfRowsInSection方法的代码:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (isSearching) {
return [searchResults count];
}
else {
if (section == 0) {
return 1;
}
else if (section == 1) {
return [basicQuantities count];
}
else if (section == 2) {
return [physicalQuantities count];
}
}
return nil;
}
Run Code Online (Sandbox Code Playgroud) objective-c uitableview uisearchbar uisearchdisplaycontroller ios
您如何更正以下内容,以便不显示任何警告?我错过了什么?
当修正searchResultsController到searchController它给了我一个错误"找不到对象"
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
} else {
cell.textLabel.text = [_content objectAtIndex:indexPath.row];
}
return cell;
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
return YES;
}
Run Code Online (Sandbox Code Playgroud) 我已将UITableView行高在Interface Builder中设置为54.0.我有一个UISearchDisplayController观点.当用户点击其中的搜索栏时,表格会正确调整大小.但是,当他们开始键入(并且实际进行搜索)时,行高度会降低.在搜索点击取消之前,它会出错.
我在Apple的网站上找不到关于此行为的文档.
我已尝试在UISearchDisplayDelegate委托调用中设置行高.这可能是正确的方法,但我不知道细节,也无法使其发挥作用.
我也尝试过实施- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;.这很有效,但是我在这个列表中有数以千计的条目,并且无法获得性能.
解决这个问题的正确方法是什么?
我在xcode 4.2中使用UISearchDisplayController实现了一个UITableView.UITableView和UISearchDisplayController是在StoryBoard中创建的.我为UITableView设置了Cell Identifier(SampleCell)并像访问它一样
cell = [tableView dequeueReusableCellWithIdentifier:@"SampleCell"];
Run Code Online (Sandbox Code Playgroud)
UItableView工作正常.但是一旦我尝试搜索,应用程序崩溃,出现以下错误.
*** Assertion failure in -[UISearchResultsTableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:6072
2011-11-09 22:22:16.058 SampleApp[14362:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Run Code Online (Sandbox Code Playgroud)
我想我需要为self.searchDisplayController.searchResultsTableView单元格设置单元格标识符.但我不知道怎么做.在此先感谢您的帮助.=)
我在发布这个问题之前搜索过,但找不到任何东西.
我有一个很大的问题.我有一个滚动类型UIPageViewController作为我的应用程序的基础,有3个视图控制器.
其中一个视图控制器(listTableView)具有表视图和搜索显示控制器.
问题是,当像状态表视图一样点击状态栏时,我无法滚动到表格视图的顶部.我相信UIPageViewController正在干扰这个,但我不知道如何修复它,但我知道我需要让我的应用程序不会感到破碎.
我感谢任何提供的帮助.
我知道有人会要求代码,即使在这种情况下它是无关紧要的,但这里是为了创建UIPageViewController:
#import "MainViewController.h"
@interface MainViewController ()
@property (nonatomic, strong) UIPageViewController *pageViewController;
@property (nonatomic, strong) NSArray *contentViewControllers;
@end
@implementation MainViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageView"];
self.pageViewController.dataSource = self;
UIViewController *settings = [self.storyboard instantiateViewControllerWithIdentifier:@"Settings"];
UIViewController *listTableView = [self.storyboard instantiateViewControllerWithIdentifier:@"List"];
UIViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:@"First"];
self.contentViewControllers = [NSArray arrayWithObjects:settings,listTableView,first,nil];
[self.pageViewController setViewControllers:@[first] direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
self.view.backgroundColor = [UIColor colorWithRed:(248.0/255.0) green:(248.0/255.0) blue:(248.0/255.0) alpha:1.0];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController …Run Code Online (Sandbox Code Playgroud) objective-c uitableview uisearchdisplaycontroller ios uipageviewcontroller
我UIViewController在故事板中设置了一个tableview和UISearchDisplayController.
我正在尝试使用self.tableview中的自定义原型单元格(它连接到故事板中的主表视图).如果self.tableview在我加载视图时返回至少1个单元格,它工作正常,但如果self.tableview没有加载单元格(因为没有数据),并且我加载UISearchBar并搜索,则cellForRowAtIndexPath:方法崩溃:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomSearchCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomSearchCell" forIndexPath:indexPath];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
-(void)configureCell:(CustomSearchCell *)cell atIndexPath:(NSIndexPath *)indexPath {
User *user = [self.fetchedResultsController objectAtIndexPath:indexPath];
cell.nameLabel.text = user.username;
}
Run Code Online (Sandbox Code Playgroud)
错误:
*** Assertion failure in -[UITableViewRowData rectForRow:inSection:heightCanBeGuessed:]
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath: 0x9ef3d00> {length = 2, path = 0 …Run Code Online (Sandbox Code Playgroud) iphone objective-c uitableview uisearchdisplaycontroller ios
我有一个UIViewController,我想用serchBar显示一个tableview.就如此容易:
//viewDidLoad
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,
0,
SCREEN_WIDTH(),
SCREEN_HEIGHT())
style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
// adding uisearch bar
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
_tableView.tableHeaderView = searchBar;
//
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
Run Code Online (Sandbox Code Playgroud)
当我在uisearch栏内单击以便动画开始并且看起来它具有20px不需要的偏移时,就会出现问题
我正在使用UISearchDisplayController与新的ios 7功能displaysSearchBarInNavigationBar和不透明的导航栏.搜索显示控制器似乎错误地定位了它的视图.
我尝试插入委托方法和重新定位,但我不能让初始位置正确,也不能在旋转时.此外,这似乎是一个草率的解决方案.


ios ×7
uitableview ×6
ios7 ×3
objective-c ×3
uisearchbar ×3
iphone ×2
cocoa-touch ×1
ios5 ×1
ios6 ×1
xcode4.2 ×1