나는 단면 표에 사용중인이 NSMutableArray에서 항목 하나를 삭제하는 방법을 찾으려고합니다. 데이터 소스를 만드는 방법은 다음과 같습니다.특정 키에 대해 NSMutableArray에서 항목을 삭제하십시오.
listOfItems = [[NSMutableArray alloc] init];
NSArray *appleComputers = [NSArray arrayWithObjects:@"iPhone",@"iPod",@"MacBook",@"MacBook Pro",nil];
NSDictionary *appleComputersDict = [NSDictionary dictionaryWithObject:appleComputers forKey:@"Computers"];
NSArray *otherComputers = [NSArray arrayWithObjects:@"HP", @"Dell", @"Windows", nil];
NSDictionary *otherComputersDict = [NSDictionary dictionaryWithObject:otherComputers forKey:@"Computers"];
[listOfItems addObject:appleComputersDict];
[listOfItems addObject:otherComputersDict];
이 배열에서 "iPod"이라고 말하면 어떻게해야합니까? 나는 그들 가운데 여러 가지를 시도했지만 아래는 하나도 효과가 없었다.
[listOfItems removeObjectAtIndex:indexPath.row];
감사합니다 (여기에 문제가 ... 실제 부분에 대한 언급이 없다는 것입니다)!
UPDATE :
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSMutableArray * section = [listOfItems objectAtIndex:indexPath.section];
[section removeObjectAtIndex:indexPath.row];
[tblSimpleTable reloadData];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// some code...
}
가}
좋은 시작이지만,이 솔루션은 원본 데이터 소스를 업데이트하지 않고 삭제 된 항목이없는 새 배열 만 생성합니다. – TommyG
새로운 배열을 전혀 만들지 않습니다. 처음에 목록에 추가 한 배열을 업데이트합니다. 정적 항목이있는 샘플 코드에서 설명한 것과 다른 "원본 데이터 원본"이있는 경우 질문을 분명히해야합니다. – Steve
나는 그렇지 않습니다. listOfItems만이 유일합니다. 그러나 코드에서 listOfItems에서 "section"을 만든 다음 listOfItems의 하위 집합 인 "section"에서 객체를 제거하고 더 이상 그 객체의 일부가 아닌 객체를 제거합니다. 그래서 listOfItems는 업데이트되지 않습니다. – TommyG