我是一个排序系统,可以对数组中的数据进行排序,尽管我在即将完成时遇到了麻烦。我已经设置了所有的系统来做这件事,尽管它现在告诉我有一个错误。以下是有问题的代码片段及其给出的错误:
NSArray *filteredArray = [[patients filterUsingPredicate:search] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
它说的错误是在病人身上,它说:
Bad receiver type void
这是上下文中的代码:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIndentifier = @"cell";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:cellIndentifier forIndexPath:indexPath];
NSString *letter = [charIndex objectAtIndex:[indexPath section]];
NSPredicate *search = [NSPredicate predicateWithFormat:@"patientName beginswith[cd] %@", letter];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"patientName" ascending:YES];
NSArray *filteredArray = [[patients filterUsingPredicate:search] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
if ( nil == cell ) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
NSLog(@"indexPath.row = %d, patients.count = %d", indexPath.row, patients.count);
Patient *thisPatient = [filteredArray objectAtIndex:[indexPath row]];
cell.textLabel.text = [NSString stringWithFormat:@"%@ %@", thisPatient.patientName, thisPatient.patientSurname];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.textColor = [UIColor blackColor];
if (self.editing) {
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return cell;
}
这是经常发生的事情吗?如果是,有办法解决吗???
提前感谢
filterUsingPredicate:
是一个void方法,因此不能对其结果调用方法。此外,您也不希望在tableView:cellForRowAtIndexPath:
中过滤此数组,因为这将真正干扰您的数据。你丢弃的每一个细胞都有一些病人!
尝试:
NSArray *filteredArray = [[patients filteredArrayUsingPredicate:search] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];