0

UISearchControllerUIAlertController組合在tvOS上有UITextField時出現問題。當試圖在tvOS上輸入文本時,UISearchController與UIAlertController問題結合

我有一個UIButton,它呈現UISearchControllerUISearchResultsController

不知何故輸入視圖(鍵盤畫面)沒有顯示在屏幕上,從下面的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細胞我提出了一個UIAlertControllerUITextField。攻絲對文本字段將不顯示輸入視圖(鍵盤畫面)

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

任何想法,我做錯了什麼?

感謝

回答

0

我有類似的問題,當我與UISearchControllerUISearchResultsController工作。我通過遷移到混合應用程序來解決它。我使用searchTemplate執行搜索,並在用戶需要搜索時顯示它。但是你也可以嘗試最簡單的方式 - 你可以實現UIAlertController作爲TVML彈出窗口(你可以使用項目formTemplate來做到這一點)。