英文:
inputAccessoryView getting hidden on UISearchBar activation in UISplitViewController
问题
我遇到一个问题 - 当 UISearchBar 被激活时,inputAccessoryView 被隐藏,即使在 iPad 上取消 UISearchBar 搜索后也不会显示出来。
视频
问题的步骤
- 开始编辑 UISearchbar
- 取消 UISearchBar 编辑
- 观察编辑前后 inputAccessoryView 的可见性
故事板
请在此存储库中找到代码 - 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
Steps to the issue
- Start UISearchbar editing
- Cancel UISearchBar editing
- Observe the inputAccessoryView visibility before and after editing
Storyboard
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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论