用内容重新加载我的 tableView 后,它仍然显示为灰色,直到我点击它..为什么?

发布于 2024-10-04 18:48:28 字数 1381 浏览 0 评论 0原文

从 UISearchBar 检索搜索结果后,结果正确显示在我的表格视图中,但视图“变灰”(见下图)。感谢任何有关此问题的帮助,我在 Apple 文档中找不到解决方案。

这是我在点击“搜索”按钮时触发的代码:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
isSearchOn = YES;
canSelectRow = YES;
self.tableView.scrollEnabled = YES;

CityLookup *cityLookup = [[CityLookup alloc] findCity:searchBar.text];

if ([cityLookup.citiesList count] > 0) {
    tableCities = cityLookup.citiesList;
}

[cityLookup release];

isSearchOn = NO;

self.searchBar.text=@"";

[self.searchBar setShowsCancelButton:NO animated:YES];
[self.searchBar resignFirstResponder];
[self.navigationController setNavigationBarHidden:NO animated:YES];

    [self.tableView reloadData];

}

这就是刷新表视图的方式:

-(UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *kCellID = @"cellID";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

NSString *cellValue = [tableCities objectAtIndex:indexPath.row];



cell.textLabel.text = cellValue;
    return cell;
}

alt text

After retrieving search results from a UISearchBar, the results appear in my tableview correctly, but the view is 'greyed out' (see image below)..Any help on this is appreciated, I can't find a solution the Apple documentation.

This is my code that is fired upon hitting the Search button:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
isSearchOn = YES;
canSelectRow = YES;
self.tableView.scrollEnabled = YES;

CityLookup *cityLookup = [[CityLookup alloc] findCity:searchBar.text];

if ([cityLookup.citiesList count] > 0) {
    tableCities = cityLookup.citiesList;
}

[cityLookup release];

isSearchOn = NO;

self.searchBar.text=@"";

[self.searchBar setShowsCancelButton:NO animated:YES];
[self.searchBar resignFirstResponder];
[self.navigationController setNavigationBarHidden:NO animated:YES];

    [self.tableView reloadData];

}

And this is how the table view is being refreshed:

-(UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *kCellID = @"cellID";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}

NSString *cellValue = [tableCities objectAtIndex:indexPath.row];



cell.textLabel.text = cellValue;
    return cell;
}

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

审判长 2024-10-11 18:48:28

如果您使用带有 UISearchDisplayController 的完整包,则以下行应删除搜索界面:

[self.searchDisplayController setActive:NO animated:YES];

如果您不使用 UISearchDisplayController 我建议您检查一下,看看它是否没有不适合你的需要。

备注:您发布的代码中没有任何内容可以删除您用于灰显表视图的任何视图。因此,如果您不使用 UISearchDisplayController,请查看显示搜索界面的代码,了解需要执行哪些操作才能将其删除。

If you are using the full package with a UISearchDisplayController the following line should remove the search interface:

[self.searchDisplayController setActive:NO animated:YES];

If you are not using UISearchDisplayController I would recommend checking it out and see if it doesn't suit your needs.

Remark: There is nothing in your posted code that would remove whatever view you have used to grey out the table view. So if you are not using UISearchDisplayController look in the code that displays the search interface to see what you need to do to remove it.

梦一生花开无言 2024-10-11 18:48:28

您在点击搜索时没有隐藏搜索栏,请尝试:

[self.navigationController setNavigationBarHidden:YES animated:YES];

Your not hiding your search bar when hitting search, try:

[self.navigationController setNavigationBarHidden:YES animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文