완벽하게 작동하는 정렬 된 NSMutableArray가 있습니다.하지만 객체를 삭제하려고 시도 할 때 응용 프로그램이 손상되고 응용 프로그램을 다시로드하면 올바른 것을 삭제하지 못합니다.정렬 된 배열은 내가 원하는 것을 지우지 않습니다
이 기능은 이전에 정렬 된 배열이기 때문에이 기능을 구현하기 전에 제대로 작동했기 때문에 그 사실을 알았습니다. 문제를 해결하는 방법에 대한 단서가 없었기 때문입니다. 여기
내가 배열에서 사물을 삭제하는 데 사용하는 코드입니다 :- (void) tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
Patient *thisPatient = [patients objectAtIndex:indexPath.row];
[patients removeObjectAtIndex:indexPath.row];
if (patients.count == 0) {
[super setEditing:NO animated:YES];
[self.tableView setEditing:NO animated:YES];
}
[self deletePatientFromDatabase:thisPatient.patientid];
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
그것은이 라인에서 중단되고
: 여기
[tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
은 내가 배열을 정렬하는 데 사용하는 코드 :
-(void) processForTableView:(NSMutableArray *)items {
for (Patient *thisPatient in items) {
NSString *firstCharacter = [thisPatient.patientName substringToIndex:1];
if (![charIndex containsObject:firstCharacter]) {
[charIndex addObject:firstCharacter];
[charCount setObject:[NSNumber numberWithInt:1] forKey:firstCharacter];
} else {
[charCount setObject:[NSNumber numberWithInt:[[charCount objectForKey:firstCharacter] intValue] + 1] forKey:firstCharacter];
}
}
charIndex = (NSMutableArray *) [charIndex sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:@"cell"];
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 filteredArrayUsingPredicate: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;
}
나는 어레이를 정렬 할 때 매우 일반적이라고 생각한다. . 당신이에서 테이블을 채우기하는 배열은 당신이에서 개체를 제거하는 배열과 같은하지 않기 때문에 당신이 당신의 배열이 정렬되어 있기 때문에 그것은 neccessarily 아니라 더 이상 코드
정렬 코드를 원합니까? – Hive7
tableView 대리자 메서드를 게시 할 수 있습니까? 그리고 당신이 그것을 정렬하는 코드? – Jsdodgers
어떻게 작동하도록 만들까요? – Hive7