inputAccessoryView 在 UISplitViewController 中激活 UISearchBar 时被隐藏。

huangapple go评论85阅读模式
英文:

inputAccessoryView getting hidden on UISearchBar activation in UISplitViewController

问题

我遇到一个问题 - 当 UISearchBar 被激活时,inputAccessoryView 被隐藏,即使在 iPad 上取消 UISearchBar 搜索后也不会显示出来。

视频

inputAccessoryView 在 UISplitViewController 中激活 UISearchBar 时被隐藏。

问题的步骤

  1. 开始编辑 UISearchbar
  2. 取消 UISearchBar 编辑
  3. 观察编辑前后 inputAccessoryView 的可见性

故事板

inputAccessoryView 在 UISplitViewController 中激活 UISearchBar 时被隐藏。

请在此存储库中找到代码 - InputAccessoryView_Issue,并随时将您的解决方案提交到该存储库本身或在 Stackoverflow 上提交。

TIA

英文:

I'm facing an issue - when UISearchBar is activated then inputAccessoryView gets hidden and doesn't show up even after de-activation of UISearchBar searching in iPad.

Video

inputAccessoryView 在 UISplitViewController 中激活 UISearchBar 时被隐藏。

Steps to the issue

  1. Start UISearchbar editing
  2. Cancel UISearchBar editing
  3. Observe the inputAccessoryView visibility before and after editing

Storyboard

inputAccessoryView 在 UISplitViewController 中激活 UISearchBar 时被隐藏。

Please find the code in this repo - InputAccessoryView_Issue and feel free to commit your solution in the repo itself or here in Stackoverflow.

TIA

答案1

得分: 0

我找到的解决方案是在搜索栏结束编辑后立即将详细控制器设置为第一响应者。
以下是相同的示例代码:

  1. extension NSNotification.Name {
  2. static let SearchbarEndEditing = NSNotification.Name("SEARCHBAR_END_EDITING")
  3. }
  4. func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
  5. NotificationCenter.default.post(name: .SearchbarEndEditing, object: nil)
  6. }
  7. DetailViewController
  8. override func viewDidLoad() {
  9. super.viewDidLoad()
  10. NotificationCenter.default.addObserver(self,
  11. selector: #selector(handleSearchbarEndEditing),
  12. name: .SearchbarEndEditing,
  13. object: nil)
  14. }
  15. @objc private func handleSearchbarEndEditing(_ sender: NSNotification) {
  16. becomeFirstResponder()
  17. view.becomeFirstResponder()
  18. }
  19. 这对我有用,希望对其他人也有用!
英文:

The solution that I found was to make the detail controller as first responder immediately after Searchbar ends editing.
Below is the sample code for the same:

  1. extension NSNotification.Name {
  2. static let SearchbarEndEditing = NSNotification.Name("SEARCHBAR_END_EDITING")
  3. }
  4. func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
  5. NotificationCenter.default.post(name: .SearchbarEndEditing, object: nil)
  6. }

And in DetailViewController:

  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3. NotificationCenter.default.addObserver(self,
  4. selector: #selector(handleSearchbarEndEditing),
  5. name: .SearchbarEndEditing,
  6. object: nil)
  7. }
  8. @objc private func handleSearchbarEndEditing(_ sender: NSNotification) {
  9. becomeFirstResponder()
  10. view.becomeFirstResponder()
  11. }

It worked for me and hopefully, it works for everyone else as well!

huangapple
  • 本文由 发表于 2023年5月6日 17:30:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76188148.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定