Could anybody please explain how to properly implement the tableView:commitEditingStyle:forRowAtIndexPath:
method so that I could properly delete an item from the backing array and display only the items that I haven't deleted yet?
Here's what I have so far:
@interface ViewController : UIViewController <UITableViewDelegate,UITableViewDataSource>
{
IBOutlet UITableView *tableView;
NSArray *allItems;
NSMutableArray *displayItems;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
allItems = [[NSArray alloc] initWithObjects:@"One",@"Two",@"Three",@"Four",@"Five",@"Six",@"Seven", nil];
displayItems = [[NSMutableArray alloc] initWithArray:allItems];
}
-(UITableViewCell*) tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = [displayItems objectAtIndex:indexPath.row];
return cell;
}
@end