0

我无法以编程方式重置/替换搜索查询字符串。我试图从 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 = @"";
    }
}
4

1 回答 1

1

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

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

希望能帮助到你。

于 2018-07-16T08:43:22.753 回答