【发布时间】:2011-08-27 18:44:47
【问题描述】:
我试图弄清楚如何从我用于分区表的 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];
(这里的问题是实际部分没有参考...)
谢谢!
更新:这是我删除行的地方:
- (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...
}
}
【问题讨论】:
标签: iphone objective-c xcode nsarray