【问题标题】:UITableView does't scroll after go to another viewcontroller from searchbar result table and come back从搜索栏结果表转到另一个视图控制器并返回后,UITableView 不滚动
【发布时间】:2012-11-18 21:02:27
【问题描述】:

我有一个在单元格中显示数据的 UITableViewController。在viewWillAppear 中,我使用此方法self.tableView.tableHeaderView =headerView; 向tableHeaderView 添加了一个UIView

headerView 中,我以编程方式添加了一个 UISearchBar 和一个 UISegmentControl。我这样设置 UISearchBar 委托

self.searchDisplay.delegate = self;
self.searchDisplay.searchBar.delegate = self;
self.searchDisplay.searchResultsDataSource = self;
self.searchDisplay.searchResultsTableView.delegate = self;

searchDisplayUISearchDisplayController

搜索工作完美,但我的问题是当我从 searchResultsTableView 中选择一个单元格并在 UINavigationController 中触摸后退按钮时转到另一个视图控制器并返回此视图时,表格不再滚动。

我在viewDidLoadviewWillAppear中添加了这两个方法,但还是不行

self.tableView.bounces = YES;
self.tableView.scrollEnabled = YES;

当我在没有搜索的情况下从表中选择一行并返回时,它工作得很好。

有什么问题?

【问题讨论】:

  • 你在 didSelectRowAtIndexpath: 方法中有什么
  • @R.A : 我有这个方法 performSegueWithIdentifier: sender:
  • 将您的viewWillAppear 代码移至viewDidLoad

标签: ios uitableview scroll uisearchbar


【解决方案1】:

您实际上在视图上使用了两个表视图,(self.tableViewself.searchDisplay.searchBarTableView)一个用于显示数据,一个用于显示搜索到的数据。我认为 searchViewController 在 segue 之后停留在屏幕上。

有一个技巧可以在单个 tableView 中显示整个数据和搜索结果(无需使用UISearchDisplayController

只需执行以下操作即可显示搜索结果:

self.tableView.dataSource = self;
self.tableView.delegate = self;

对于实际数据,您可以清空UISearchBar,然后将整个数据加载到表视图数据源中。

【讨论】:

  • 非常感谢它的工作:)
【解决方案2】:

尝试放置您的

self.tableView.bounces = YES;
self.tableView.scrollEnabled = YES;

- (void) viewWillAppear:(BOOL)animated 而不是viewDidLoad。我相信viewDidLoad 在从其他视图返回时不会被调用,只有在被创建时才会被调用。

【讨论】:

  • 我之前做过,但什么也没发生
猜你喜欢
  • 2016-05-12
  • 1970-01-01
  • 2012-07-19
  • 2016-11-09
  • 1970-01-01
  • 2019-01-24
  • 1970-01-01
  • 2018-04-13
  • 1970-01-01
相关资源
最近更新 更多