我不想在我的服务器处理搜索查询时显示“无结果”文本。
我找出了包含标签的表格单元格的确切坐标,并尝试覆盖它。
self.noResultsCoverView = [[[UIView alloc] initWithFrame:CGRectMake(
0.0,
44.0,
320.0,
43.0
)] autorelease];
self.noResultsCoverView.backgroundColor = [UIColor whiteColor];
[self.searchDisplayController.searchResultsTableView addSubview:self.noResultsCoverView];
令我懊恼的是,我的封面位于表格视图上方,但标签下方。我需要将封面放在标签上方。searchResultsTableView::bringSubviewToFront
不起作用,这让我相信该标签不是searchResultsTableView
at all.
顺便说一句,这个堆栈溢出答案对我来说不太管用。它在第一次搜索时有效,但在后续搜索中会闪烁一个奇怪的黑色封面。
这应该可以正常工作。返回至少一个单元格的代码:
BOOL ivarNoResults; // put this somewhere in @interface or at top of @implementation
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
if (filteredList.count == 0) {
ivarNoResults = YES;
return 1;
} else {
ivarNoResults = NO;
return [filteredList count];
}
}
// {…}
// return the unfiltered array count
}
以及“显示”干净的单元格:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView && ivarNoResults) {
static NSString *cleanCellIdent = @"cleanCell";
UITableViewCell *ccell = [tableView dequeueReusableCellWithIdentifier:cleanCellIdent];
if (ccell == nil) {
ccell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cleanCellIdent] autorelease];
ccell.userInteractionEnabled = NO;
}
return ccell;
}
// {…}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)