0

我是一个排序系统,可以对数组中的数据进行排序,尽管我在即将完成时遇到了麻烦。我已经设置了所有系统来执行此操作,尽管它现在告诉我我有一个错误。这是它给出的有问题的代码片段和错误:

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;
}

这是一件经常发生的事情,如果是这样,有办法解决吗???

提前致谢

4

1 回答 1

5

filterUsingPredicate:是一个 void 方法,因此您不能对其结果调用方法。此外,您不想在内部过滤此数组,tableView:cellForRowAtIndexPath:因为这会真正弄乱您的数据。你会丢弃一些病人的每一个细胞!

尝试:

NSArray *filteredArray = [[patients filteredArrayUsingPredicate:search] sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
于 2013-08-18T08:06:41.310 回答