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

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

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

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

extension NSNotification.Name {
     static let SearchbarEndEditing = NSNotification.Name("SEARCHBAR_END_EDITING")
}

func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
    NotificationCenter.default.post(name: .SearchbarEndEditing, object: nil)
}

DetailViewController中

override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(handleSearchbarEndEditing),
                                           name: .SearchbarEndEditing,
                                           object: nil)
}

@objc private func handleSearchbarEndEditing(_ sender: NSNotification) {
    becomeFirstResponder()
    view.becomeFirstResponder()
}

这对我有用,希望对其他人也有用!
英文:

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:

extension NSNotification.Name {
     static let SearchbarEndEditing = NSNotification.Name("SEARCHBAR_END_EDITING")
}

func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
    NotificationCenter.default.post(name: .SearchbarEndEditing, object: nil)
}

And in DetailViewController:

override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(handleSearchbarEndEditing),
                                           name: .SearchbarEndEditing,
                                           object: nil)
}

@objc private func handleSearchbarEndEditing(_ sender: NSNotification) {
    becomeFirstResponder()
    view.becomeFirstResponder()
}

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:

确定