UISearchController
とUIAlertController
とを組み合わせて、tvOSにUITextField
が含まれていると問題が発生します。tvOSにテキストを入力しようとすると、UISearchControllerとUIAlertControllerの問題が発生する
私はをUISearchResultsController
と表しています。これはUIButton
です。問題のテストプロジェクトのリンク、およびビデオデモと同様に、以下UIAlertController
コードからUITextField
を打つとき
ViewController.swift - 私はUITextField
でUIAlertController
を提示collectionView
からセルをタップする - ここから私は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を示しました。入力ビューが表示されませんそのテキストフィールドをタップ(キーボード画面)
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
すべてのアイデア、私が何か間違ったことをやっていますか?私はUISearchController
とUISearchResultsController
で働いていたとき
おかげ