2013-10-15 13 views
8

Ho un UITableView, sto tentando di eliminare una riga quando la modalità di modifica è attiva ma commitEditingStyle non viene attivato.commitEditingStyle non viene attivato

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

Voglio solo cancellare una riga?

Questo è il modo in mostro il mio 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]; 
} 

ho creato UITableView utilizzando l'interfaccia Xcode.

-(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

risposta

8

spara quando si tocca DELETE tasto, non il meno ... ed Elimina pulsanti del Tableview non mostra propably a causa della larghezza della Tableview ...

0

edit: dopo aver guardato il codice, penso charty è corretta.

assicuratevi di controllare lo stile di modifica e apportare le modifiche necessarie all'origine dati. qualcosa di simile:

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

no, Non l'ho dimenticato .. L'ho impostato .. – onivi

+0

per favore mostra il codice che hai usato per creare e presentare UITableView e UIPopover, così come la definizione del metodo per @selector (Fatto :) – Nick

+0

ha aggiornato la mia risposta. – onivi

Problemi correlati