首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试在tvOS上输入文本时出现UISearchController和UIAlertController问题

尝试在tvOS上输入文本时出现UISearchController和UIAlertController问题
EN

Stack Overflow用户
提问于 2016-09-14 20:57:14
回答 1查看 301关注 0票数 0

UISearchController与在tvOS上具有UITextFieldUIAlertController组合时出现问题。

我有一个UIButton,它提供一个带有UISearchResultsControllerUISearchController

当从UIAlertController点击UITextField时,不知何故输入视图(键盘屏幕)没有显示在屏幕上

下面的代码,以及测试项目链接,以及问题的视频演示。

ViewController.swift -从这里我展示了searchController

代码语言:javascript
复制
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中的单元格时,我会显示一个带有UITextFieldUIAlertController。点击该文本字段将不会显示输入视图(键盘屏幕)

代码语言:javascript
复制
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

有什么想法,我做错了什么吗?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-09-15 14:28:00

当我使用UISearchControllerUISearchResultsController时,我遇到了类似的问题。我通过迁移到混合应用程序解决了这个问题。我用searchTemplate实现了一个搜索,并在用户需要搜索的时候显示出来。但您也可以尝试最简单的方法--您可以将UIAlertController实现为TVML-popup (您可以使用item formTemplate来实现)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39491037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档