小编Mel*_*Mel的帖子

在tvos中更改焦点时如何在UISearchController中关闭键盘?

我是tvos的新手,我正在尝试实现一个UISearchController视图,在我的SearchResultsViewController中,我有两个UICollectionViews一个显示在另一个上面: 在此输入图像描述

问题是当用户向下滑动以选择UICollectionView中的一个项目时,键盘不会被忽略.即使向上滑动以选择键盘也无法完全向上滚动,因此无法看到您正在键入的内容.结果视图是这样的: 在此输入图像描述

理想情况下,当用户向下滑动以关注界面中的任何其他内容时,我想关闭键盘.我查看了Apple的tvos UIKit目录,他们的示例显示了一个UISearchController,它在更改焦点时解除了键盘,但我没有看到他们正在做任何不同的事情.

这是我用来点击按钮时设置我的UISearchController的代码:

@IBAction func onSearchButton(sender: AnyObject) {
    guard let resultsController = storyboard?.instantiateViewControllerWithIdentifier(SearchResultsViewController.storyboardID) as? SearchResultsViewController else { fatalError("Unable to instantiate a SearchResultsViewController.") }

    // Create and configure a `UISearchController`.
    let searchController = UISearchController(searchResultsController: resultsController)
    searchController.searchResultsUpdater = resultsController
    searchController.hidesNavigationBarDuringPresentation = false

    let searchPlaceholderText = NSLocalizedString("Search for a Show or Movie", comment: "")
    searchController.searchBar.placeholder = searchPlaceholderText

    // Present the search controller from the root view controller.
    guard let rootViewController = view.window?.rootViewController else { fatalError("Unable to get root view …
Run Code Online (Sandbox Code Playgroud)

swift uisearchcontroller tvos

7
推荐指数
1
解决办法
1625
查看次数

无法在Swift中覆盖NSDictionary的初始化程序

我正在尝试在Swift中扩展类NSDictionary以包含在init()上设置的NSDate.当我添加自定义init()时,我得到编译器错误:

'required'初始化程序'init(dictionaryLiteral :)'必须由'NSDictionary'的子类提供

但是,当我使用自动完成添加初始化程序时,我收到以下错误:

来自扩展的声明无法覆盖

有没有办法覆盖NSDictionary的初始化程序或者Swift只是不能处理它?

这是我的班级:

class DateParam : NSDictionary {
    let date : NSDate

    init(date: NSDate) {
        super.init()
        self.date = date
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    required convenience init(dictionaryLiteral elements: (NSCopying, AnyObject)...) {
        fatalError("init(dictionaryLiteral:) has not been implemented")
    }
}
Run Code Online (Sandbox Code Playgroud)

nsdictionary swift swift-extensions

5
推荐指数
1
解决办法
1123
查看次数