将UISearchController与在tvOS上具有UITextField的UIAlertController组合时出现问题。
我有一个UIButton,它提供一个带有UISearchResultsController的UISearchController。
当从UIAlertController点击UITextField时,不知何故输入视图(键盘屏幕)没有显示在屏幕上
下面的代码,以及测试项目链接,以及问题的视频演示。
ViewController.swift -从这里我展示了searchController
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonAction(_ sender: UIButton) {
let searchResultsController = storyboard?.instantiateViewController(withIdentifier:"SearchResultsViewController")
let searchController = UISearchController(searchResultsController: searchResultsController)
show(searchController, sender: self)
}
}SearchResultsViewController.swift -当点击collectionView中的单元格时,我会显示一个带有UITextField的UIAlertController。点击该文本字段将不会显示输入视图(键盘屏幕)
class SearchResultsViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UISearchResultsUpdating {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func updateSearchResults(for searchController: UISearchController) {
collectionView.reloadData()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let ac = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
ac.addTextField { (textfield) in
textfield.placeholder = "Action here doen't show the keyboard to input text..."
}
let ok = UIAlertAction(title: "Ok", style: .default) { (action) in
print(ac.textFields?.first?.text)
}
ac.addAction(ok)
present(ac, animated: true, completion: nil)
}
}视频链接here
测试项目链接here
有什么想法,我做错了什么吗?
谢谢
发布于 2016-09-15 14:28:00
当我使用UISearchController和UISearchResultsController时,我遇到了类似的问题。我通过迁移到混合应用程序解决了这个问题。我用searchTemplate实现了一个搜索,并在用户需要搜索的时候显示出来。但您也可以尝试最简单的方法--您可以将UIAlertController实现为TVML-popup (您可以使用item formTemplate来实现)。
https://stackoverflow.com/questions/39491037
复制相似问题