commitEditingStyle没有被触发

我有一个UITableView,我试图删除一个行,当编辑模式是活跃的,但未触发commitEditingStyle。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; } cell.text=[NSString stringWithFormat:@"Row Number %d",indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"trying to delete a row.."); } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 6; } -(void)Edit:(id)sender //Active editing mode { [self.table setEditing:YES animated:YES]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done:)]; } 

我只想删除一行?

这是我如何显示我的popover:

 UIPopoverController *popover; -(IBAction)open:(id)sender { CGRect r=((UIButton*)sender).frame; CGRect tRect=[((UIButton*)sender) convertRect:((UIButton*)sender).frame toView:self.view]; tRect.origin.x=r.origin.x; Popover *firstViewCtrl = [[Popover alloc] init]; UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:firstViewCtrl]; navbar.preferredContentSize = CGSizeMake(300, 300); popover = [[UIPopoverController alloc] initWithContentViewController:navbar]; popover.delegate = self; popover.popoverContentSize = CGSizeMake(300, 300); CGRect popRect = CGRectMake(0, 0, 200, 200); [popover presentPopoverFromRect:popRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; // [popover presentPopoverFromRect:tRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; } 

我使用Xcode接口创build了UITableView。

 -(void)Done:(id)sender { [self.table setEditing:NO animated:NO]; //[self.table endEditing:true]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(Edit:)]; } 

在这里输入图像说明

它触发时,您触摸DELETEbutton,而不是减号…并删除button上的tableview不显示propably由于你的tableview的宽度…

编辑:在看你的代码后,我认为charty是正确的。

一定要检查编辑风格,并对数据源进行必要的调整。 就像是:

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { NSLog(@"deleting"); [_resultsArray removeObjectAtIndex:indexPath.row]; [tableView reloadData]; } }