我有一个UISearchDisplayController,它位于我的UITableView的headerview中.我想知道什么时候显示UISearchDisplayController的searchResultsTableView所以我可以做一些其他的操作:
if(self.tableView == self.searchDisplayController.searchResultsTableView)
Run Code Online (Sandbox Code Playgroud)
即使显示searchResultsTableView,也会一直返回true.我怎么能搞清楚这一点?
iphone cocoa-touch objective-c uitableview uisearchdisplaycontroller
在我的tableview中有我从UITableViewCell类初始化的自定义单元格.我有第一个记录字母的部分,并有一个动态创建的indexPath.
我想在我的tableview中添加一个搜索显示控制器.所以我做了,创建了所有过滤数据的方法.我确信我的功能运行良好,因为我打印数组计数以筛选搜索结果.
我的问题是第一次加载视图时,数据在屏幕上.但当我点击搜索输入并输入一个字母时,我得到的'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'错误.在我使用断点后,我看到我的自定义单元格在搜索后为零.数据存在,但未初始化单元格.
这是我用于自定义单元初始化的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ObjectCell";
SpeakerCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *myObject = [[sections valueForKey:[[[sections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.label1.text = [myObject objectForKey:@"myValue"];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我认为在将控件放入IB时我犯了一个错误.所以我添加了对象的截图:

我的表视图的连接检查器
我的搜索显示控制器的连接检查器

编辑:问题实际上已经解决,我使用了UISearchBar而不是搜索显示控制器,但我想这个问题仍然没有解决.所以我愿意尝试任何方法让它发挥作用.
iphone xcode objective-c uitableview uisearchdisplaycontroller
我UISearchBar在UITableView一个表头.当我按下UISearchBar开始搜索时,会触发此方法
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
Run Code Online (Sandbox Code Playgroud)
对UISearchDisplayController.
但结果就是这样;

正如你所看到的,没有光标,我可以开始输入和搜索,一切正常.此外,它仅在iOS 7中不可见.但是,使用iOS 6.1和iOS 7.1 Beta 3,我可以看到光标.那么如何才能使UISearchBar游标可见或如何在我的UISearchBar中添加游标?
我有一个UITableViewController包含a UISearchDisplayController和UISearchBar标准方式的T (在nib中定义的所有内容).然后由一些其他视图控制器以标准方式将T包含为子视图控制器.
搜索栏正确显示:

但当我点击搜索栏实际搜索时,搜索栏会变得更高,搜索栏内的内容会下降大约20像素(呃,状态栏的高度?巧合?)就像这样:

那是怎么回事?太高了.此外,使它看起来像这样的动画是笨拙的.有什么方法可以防止这种难看的增长?
我正在使用UISearchController在UITableView中显示搜索栏和结果.我设法正确设置它,但是当我搜索结果然后选择tableview中的一行,并将新的视图控制器推送到导航堆栈时,我希望搜索栏不再可见.但是,当我尝试这个时,第一个视图控制器中的搜索栏在第二个视图控制器中可见:
if (self.searchController == nil) {
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[];
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
}
Run Code Online (Sandbox Code Playgroud)
一种选择是调用self.searchController setActive:NO]内部didSelectRowAtIndexPath:但没有办法在没有每次从中选择搜索结果时关闭搜索栏的分散动画的情况下执行此操作.
有没有人有同样的问题?有没有办法告诉UISearchController在推送时隐藏搜索栏?我在使用UISearchDisplayController时工作正常
uitableview uisearchbar uisearchdisplaycontroller ios uisearchcontroller
我的应用程序的表视图不占用全屏高度,因为我在底部允许50px的横幅.
当我开始在搜索栏中输入内容时,搜索结果表视图会更大; 它填充搜索栏和标签栏之间的所有可用屏幕空间.这意味着最后一个搜索结果被横幅遮挡了.
如何指定UISearchDisplayController使用的表视图的大小?我可以看到没有边界或框架属性.
编辑添加屏幕截图:
这是在IB中设置表视图的方式.它比合成标签栏短50px.
alt text http://iphone.lightwood.net/StackOverflow/gstableviewinib.png
这就是内容正常显示的方式.我已经滚到了最底层. alt text http://iphone.lightwood.net/StackOverflow/gstableviewatbottom.png
这是搜索时显示的方式.我再次滚动到最底层.如果我停用横幅广告,我会看到搜索显示表向下展开到标签栏.
alt text http://iphone.lightwood.net/StackOverflow/gssearchviewatbottom.png
我有一个带有搜索栏的非tableview视图,虽然它工作正常,搜索显示控制器会隐藏表格视图,并在搜索栏中出现空字符串时覆盖暗灰色视图.我希望它在空字符串位于搜索栏中时显示预加载的数据,而不是隐藏表格视图并覆盖搜索栏下方的暗灰色视图.就像Safari for iOS中的Google搜索栏一样.
我之前在stackoverflow上发现了一个类似的问题: UISearchDisplayController - 如何预加载searchResultTableView,我真的无法让它工作.
我没有问题获取预加载数据并设置当前数据,但我不知道如何阻止displaycontroller删除searchResultsTableView.
提前致谢.
objective-c uisearchbar uisearchdisplaycontroller ios xcode4.3
我有一个NSFetchedResultController不同的部分.我尝试搜索时发生崩溃UISearchDisplayController:
*** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit/UIKit-2372/UITableViewRowData.m:1630
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath 0x1d2c4120> 2 indexes [0, 1])'
Run Code Online (Sandbox Code Playgroud)
我检查了,我的搜索数组确实有两个条目(预期结果):
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
Run Code Online (Sandbox Code Playgroud)
它返回1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
它返回2
有趣的是,如果我只有一个部分,那就完美了.
请帮忙!:)
cocoa-touch uitableview uisearchdisplaycontroller nsfetchedresultscontroller ios
我在我的应用程序中使用了UISearchDisplayController.当用户选择返回的搜索结果中的项目时,我将停用UISearchDisplayController.取消激活控制器会清除用户键入的文本.我想把它留在那里.我可以通过在取消激活控制器后再次设置它来强制文本回到UISearchBar.
像这样:
NSString* searchText = self.searchDisplayController.searchBar.text;
[self.searchDisplayController setActive:NO animated:YES];
self.searchDisplayController.searchBar.text = searchText;
Run Code Online (Sandbox Code Playgroud)
哪个有效.
但是,如果我没有为停用呼叫设置动画,我会看到时间问题.像这样调用setActive:
NSString* searchText = self.searchDisplayController.searchBar.text;
[self.searchDisplayController setActive:NO animated:NO];
self.searchDisplayController.searchBar.text = searchText;
Run Code Online (Sandbox Code Playgroud)
导致UISearchDisplayController再次变为活动状态!
是否有一种方法可以设置UISearchBar的文本,而不会使与之关联的UISearchDisplayController变为活动状态?有什么其他建议来解决这种行为吗?
我希望我的搜索栏将其背景向上扩展到状态栏下方,如下所示:

这是上图中的相应代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.searchBar = [[UISearchBar alloc] init];
self.searchBar.delegate = self;
[self.view addSubview:self.searchBar];
self.searchBar.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *views = @{@"v":self.searchBar,
@"topLayoutGuide":self.topLayoutGuide};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide][v]" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]|" options:0 metrics:nil views:views]];
[self.searchBar setBackgroundImage:[UIImage imageNamed:@"searchbarBG"] forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
}
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
Run Code Online (Sandbox Code Playgroud)
当我UISearchDisplayController通过在viewDidLoad方法的末尾附加以下行将搜索栏添加到a时出现问题:
self.mySearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:

请注意,图像看起来有所剪裁.这与我在代码中将UIBarPositionTopAttached更改为UIBarPositionTop时的情况不同:

被剪裁的图像让我想到了clipsToBounds,我可以通过在以下结尾添加这段代码来正确显示搜索栏viewDidLoad:
for (UIView *subview in self.searchBar.subviews) {
subview.clipsToBounds = NO;
} …Run Code Online (Sandbox Code Playgroud) ios ×6
uisearchbar ×5
uitableview ×5
iphone ×4
objective-c ×3
cocoa-touch ×2
ios7 ×2
xcode ×1
xcode4.3 ×1