【问题标题】:UISearchBar not moving with Tableview when scrolling down向下滚动时 UISearchBar 不随 Tableview 移动
【发布时间】:2013-02-05 21:37:30
【问题描述】:

UISearchBar 在向下滚动时不随 Tableview 一起移动。

我不想单独放置滚动条。它是一个要求。 下面是代码。

customSearchBar = [[UISearchBar alloc] init];
customSearchBar.delegate = self;
[customSearchBar sizeToFit];
objListTable.tableHeaderView = customSearchBar;

【问题讨论】:

  • 而不是tableHeaderView 将搜索栏放在tableview 上,我们可以使用其他东西吗?我的猜测是 tableHeaderView 不会让它向下滚动。如果我错了,请纠正/

标签: ios objective-c xcode uisearchbar


【解决方案1】:

需要包含一个 View 并在其上添加 UISearchbar,或者提供 Header 视图的高度。默认情况下,它被视为 0.0。

如果你想使用

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

该方法分配一个高度为默认UISeachBarheight 的视图。并在其上添加UISearchBar。

或者在你的代码上添加一个UIView,默认UISearchBar高度添加UISearchBar。它将按您的预期工作。

【讨论】:

  • 我们如何指定页眉的高度。我迷路了。找不到正确的属性。
  • 更新了我的答案,请检查。
  • 标头的高度不是一个属性,它是一个UITableViewDelegate(或DataSource,记不得了)回调。
  • 所以@GuyKogus:你能指定委托方法吗?
  • tableView:heightForHeaderInSection: 这会让你花整整 10 秒才能找到自己……
猜你喜欢
  • 2013-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-05
  • 1970-01-01
  • 1970-01-01
  • 2012-09-08
  • 1970-01-01
相关资源
最近更新 更多