9

I've a UITableView, I am trying to delete a row when editing mode is active but commitEditingStyle is not fired.

- (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:)];
}

I just want to delete a row?

This is how I show my 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];
}

I created UITableView using Xcode interface.

-(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:)];
}

enter image description here

onivi
  • 1,348
  • 3
  • 17
  • 25

2 Answers2

8

it fires when you touch DELETE button, not the minus... And delete buttons on your tableview doesn't show propably due to your tableview's width...

amone
  • 3,712
  • 10
  • 36
  • 53
0

edit: after looking at your code, I think charty is correct.

be sure to check for the editing style, and make the necessary adjustments to your data source. something like:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSLog(@"deleting");
        [_resultsArray removeObjectAtIndex:indexPath.row];
        [tableView reloadData];
    }
}
Axe
  • 6,285
  • 3
  • 31
  • 38
Nick
  • 2,361
  • 16
  • 27
  • please show the code you used to create and present the UITableView and UIPopover, as well as the method definition for @selector(Done:) – Nick Oct 15 '13 at 19:43