【发布时间】:2015-07-22 16:36:52
【问题描述】:
这是代码
- (void)viewDidLoad {
[super viewDidLoad];
_queriedResults = [[NSMutableArray alloc]init]
}
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[_queriedResults addObjectsFromArray:[self searchBarQuery:[searchText lowercaseString]]];
}
-(NSArray*)searchBarQuery:(NSString*)searchedUser{
NSArray * users;
PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:[searchedUser lowercaseString]];
users = [query findObjects];
return users;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text = [_queriedResults[indexPath.row]username];
return cell;
}
所以这些是我在视图控制器类中使用的主要功能。我已经进行了一些调试,并且 queriedResults 确实成功地获取了我正在搜索的用户的名称,但是当 queriedResults 最终在其数组中包含值时,我的 tableView:cellForRowAtIndexPath 使应用程序崩溃。我已经设置了单元格标识符,并且当我使用普通的临时数组对其进行测试时,代码工作正常。我不知道为什么从解析数据库中查询它时它会崩溃。
这是我在应用崩溃时收到的消息。
NSInternalInconsistencyException', reason: '无法使用标识符单元格出列单元格 - 必须为标识符注册一个 nib 或类或连接情节提要中的原型单元格'
我也遇到了这个错误 -
-[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:] 中的断言失败,
但是我想我已经注册了单元格。这就是为什么在我测试时它可以与其他数组一起使用。我不知道代码有什么问题。
【问题讨论】:
-
_queriedResults是您在测试时唯一更改的内容?你在使用搜索结果控制器吗? -
肯定不是 Xcode 的搜索栏崩溃了吧?
-
我正在使用搜索栏和搜索显示控制器,我也收到此错误 - 断言失败 -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:],
标签: ios objective-c searchbar