【问题标题】:Resetting the search query string in UISearchController programmatically以编程方式重置 UISearchController 中的搜索查询字符串
【发布时间】:2018-07-13 15:17:57
【问题描述】:

我未能以编程方式重置/替换搜索查询字符串。我试图从 UISearchControllerDelegate 中修改 UISearchBar 查询字符串。

我正在使用听写输入。

当命令“删除”时,searchController.searchBar.text 应该设置回@""。语音检测应继续使用空字符串正常进行。

查询字符串确实重置为@"",但语音检测停止。

如何以编程方式重置 UISearchController 中的搜索查询字符串,并且仍然能够使用语音继续输入?

- (void)updateSearchResultsForSearchController:(nonnull UISearchController *)searchController {
    NSString *searchQuery = self.searchController.searchBar.text;

    // Deletion command
    if ([self.searchController.searchBar.text hasSuffix:@"delete"]) {

        // Things that I've tried that don't work
        //[self.searchController.searchBar setText:@""];
        //self.searchController = [self.searchController init];
        //self.searchController.searchBar.text = @"";

        searchQuery = @"";
    }
}

【问题讨论】:

    标签: objective-c uisearchbar uisearchcontroller uisearchbardelegate uisearchresultscontroller


    【解决方案1】:

    此功能在 iOS 中尚不可用。一旦您尝试清除 searchBar 的 TextField 中的文本,它就会将键盘模式更改为键盘输入。

    因此,结论是,您只能使用听写向 textField 提供输入,但无法清除它。用户必须手动执行该过程才能再次更改为听写输入。

    希望对你有帮助。

    【讨论】:

    • 同样的结论,不支持也不可能从代码重新激活语音输入。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-30
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2013-05-22
    • 2017-10-23
    相关资源
    最近更新 更多