编辑UISearchBar并解除UITableViewController时应用程序崩溃

时间:2013-07-19 23:36:24

标签: ios uitableview

我看到一个错误,如果我在编辑嵌入UISavigationBar的titleView的UISearchBar时点击导航控制器中的后退按钮,我的应用程序崩溃了。主VC是一个UITableViewController,使用[parentView.navigationController pushViewController:myTableView animated:YES];

将其推送到视图堆栈

以下是我在viewDidLoad中用于创建UISearchBar的代码:

UISearchBar *customSearch = [[UISearchBar alloc] initWithFrame:
                                CGRectMake(0,0, 320, 44)];
customSearch.delegate = self;
customSearch.placeholder = @"Some placeholder text";
self.navigationItem.titleView = customSearch;

这些是我对UISearchBar委托的委托实现 - 句柄搜索只是更新支持tableView的数组并调用[self.tableview reloadData]:

- (void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
    searchBar.showsCancelButton = YES;
}
- (void) searchBarTextDidEndEditing:(UISearchBar *)searchBar {
    searchBar.showsCancelButton = NO;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [self handleSearch:searchBar];
    [searchBar resignFirstResponder];
}
- (void) searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
    [self handleSearch:searchBar];
}

- (void)handleSearch:(UISearchBar *)searchBar {
    [self updateFilteredData:searchBar.text];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
    searchBar.text = @"";
    [self handleSearch:searchBar];
    [searchBar resignFirstResponder];
}

我从崩溃中得不到任何信息 - 只是一个sigkill。如果我不编辑UISearchBar,它可以正常工作。我已经尝试让第一个响应者辞职,但它仍然崩溃。

更新 - 添加过滤数据

- (void) updateFilteredData: (NSString *) nameFilter {
    if (nameFilter.length) {
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(first_name CONTAINS[cd] %@) OR (last_name CONTAINS[cd] %@)", nameFilter, nameFilter];
      self.filteredData = [self.data filteredArrayUsingPredicate:predicate];
    } else {
        self.filteredData = self.data;
    }
    [self.tableView reloadData];
}

我在viewWillDisappear中尝试了以下所有+所有这些。它们都成功运行,searchBar引用是有效的UISearchBar。

-(void)viewWillDisappear:(BOOL)animated {
    UISearchBar *mySearchBar = (UISearchBar *)self.navigationItem.titleView;
    [mySearchBar resignFirstResponder];
    mySearchBar.delegate = nil;
    self.navigationItem.titleView = nil;
    for (UIView *view in [mySearchBar subviews] ) {
        [view removeFromSuperview];
    }
    [mySearchBar removeFromSuperview];
    [super viewWillDisappear:animated];
}

它可能不是搜索栏的东西,我只是在编辑搜索栏时一直看到崩溃 - 它可能是视图隐藏键盘并尝试在TableView同时重绘下面的单元格正在被解构。

0 个答案:

没有答案