ios - 单击搜索栏文本字段中的复制或剪切选项时,应用崩溃

标签 ios crash textfield searchbar

在选项中,粘贴和定义是确定的,但是当我单击副本或剪切时,它将崩溃。我试图删除除搜索栏以外的所有代码,但它也无法正常工作。我尝试覆盖textfield方法,但搜索栏 subview 不包含UITextField
这是我的代码

_searchBar = [[UISearchBar alloc] initWithFrame:self.topBar.bounds];
    [_searchBar setPlaceholder:LS(@"Search", @"")];
    [_searchBar setDelegate:self];

    _searchController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
    _searchController.delegate = self;
    _searchController.searchResultsDataSource = self;
    _searchController.searchResultsDelegate = self;

    if( _scopeButtonTitles ) {
        _searchBar.scopeButtonTitles = _scopeButtonTitles;
        _searchBar.showsScopeBar = YES;
    }

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [_searchBar resignFirstResponder];
}

#pragma mark - UISearchBarDelegate

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    _searchResultsAvailable = NO;
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
     self.loadingTitle = [NSString stringWithFormat:@"%@ %@%@",LS(@"Searching", @""),self.title?self.title:@"",@"..."];
    _searchResultsAvailable = YES;
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    _searchResultsAvailable = NO;
}

最佳答案

我已经多次启动该错误,然后在我的应用中发现了错误。
它只需要重写searchBar的复制和剪切方法。
在我重写方法后,错误消失了

关于ios - 单击搜索栏文本字段中的复制或剪切选项时,应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28472879/

相关文章:

SwiftUI TextField 简单示例不起作用

java - TextField selectAll 的效果减半

ios - iOS 中的动画文本内容 - 相当于 Android ValueAnimator

java - Android蓝牙程序立即崩溃

android - 是否可以使用 React Native 构建 Android SDK 和 iOS SDK?

c# - Unity 编辑器在使用 mfperfhelper.dll 访问冲突时崩溃

user-interface - Monkey Runner是否需要任何脚本语言来运行

python - textfield 和 charfield 的渲染去掉了额外的空白(Django/Python)

ios - 如何在 iOS 7 上的三个 ViewController 之间使用 Core Data 传递数据

ios - 使大型 UIView 适合内容 View