如果我的搜索谓词返回nil,则尝试弹出UIAlert
||
如果用户进行搜索并且谓词返回nil,我将尝试弹出一条警告“未找到记录”的警报。
我尝试了此操作,但从未收到警报。我只是得到一个空的tableview。
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
if (self.sBar.text != nil){
NSPredicate *template = [NSPredicate predicateWithFormat:@\"name contains[cd] $SEARCH OR optionOne contains[cd] $SEARCH OR optionTwo contains[cd] $SEARCH\"];
NSDictionary *replace = [NSDictionary dictionaryWithObject:self.sBar.text forKey:@\"SEARCH\"];
NSPredicate *predicate = [template predicateWithSubstitutionVariables:replace];
[fetchedResultsController.fetchRequest setPredicate:predicate];
}
[[fetchedResultsController fetchedObjects] count];
if (fetchedResultsController.fetchedObjects != nil) {
//do nothing
} else {
//display alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@\"No records match.\"
delegate:self cancelButtonTitle:@\"OK\" otherButtonTitles:nil];
[alert show];
[alert release];
}
NSError *error = nil;
if (![[self fetchedResultsController] performFetch:&error]) {
// Handle error
NSLog(@\"Unresolved error %@, %@\", error, [error userInfo]);
abort(); // Fail
}
[self.myTable reloadData];
[sBar resignFirstResponder];
}
没有找到相关结果
已邀请:
2 个回复
瞥同忙接
。谓词是一个表达式,其结果为
或
。而已。 您可以向
索取其
(返回一个数组),然后向该数组索取其
,但是只有在调用
之后才能执行此操作。
茶鬼失形