editingStyleForRowAtIndexPath n'est pas appelé (donc un bouton de suppression montre vers le haut)

StackOverflow https://stackoverflow.com/questions/2226509

  •  19-09-2019
  •  | 
  •  

Question

Je suis jouer avec UITableViewCells en mouvement, et pour une raison quelconque,

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone; //<-- bp set on it
}

est pas appelé (je l'ai mis un point d'arrêt sur lui) - de sorte que le tableau montre l'option de suppression, mais je ne veux pas. Voici mon implémentation:

@implementation MoveItController
@synthesize mList;

- (IBAction)moveButton
{
    [self.tableView setEditing:!self.tableView.editing animated:YES];

    [self.navigationItem.rightBarButtonItem setTitle:(self.tableView.editing)? @"Done" : @"Move"];
}

- (void)viewDidLoad
{
    if (mList == nil)
    {
        mList = [[NSMutableArray alloc] initWithObjects:@"$1", @"$2", @"$5", @"$10", @"$20", @"$50", @"$100", nil];
    }

    UIBarButtonItem *mvButton = [[UIBarButtonItem alloc]
                                 initWithTitle:@"Move" 
                                 style:UIBarButtonItemStyleBordered 
                                 target:self 
                                 action:@selector(moveButton)];
    self.navigationItem.rightBarButtonItem = mvButton;
    [mvButton release];
    [super viewDidLoad];
}

// Table datasource methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [mList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *moveItCellId = @"moveItCellId";


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moveItCellId];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moveItCellId] autorelease];
        cell.showsReorderControl = YES;
    }

    cell.textLabel.text = [mList objectAtIndex:[indexPath row]];
    return cell;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}

- (BOOL)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
    id object = [[mList objectAtIndex:[fromIndexPath row]] retain];
    [mList removeObjectAtIndex:[fromIndexPath row]];
    [mList insertObject:object atIndex:[toIndexPath row]];
    [object release];                 
}

- (void) dealloc
{
    [mList release];
    [super dealloc];
}

@end

Aucun avertissement au moment de la compilation.

Merci!

Était-ce utile?

La solution

Essayez de capitaliser le nom de la méthode appropriée

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

C'est le S dans editingStyleForRowAtIndexPath capitalisé. sélecteurs ObjC sont sensibles à la casse. La vue de la table ne pense pas délégué de elle répond à la méthode que vous essayez de fournir une valeur de retour à.

Autres conseils

Vous devez définir la sélection multiple de NO en mode d'édition

self.tableview.allowsMultipleSelectionDuringEditing = NO;

Une autre raison pourrait être que vous devez également mettre en œuvre

- (void)tableView:(UITableView *)tableView
  commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
  forRowAtIndexPath:(NSIndexPath *)indexPath

Une autre raison de editingStyleForRowAtIndexPath (et d'autres délégués) ne pas être appelé est si le contrôle ne dispose pas de sortie de délégué connecté au propriétaire du fichier.

Oui, cela est évident, mais il est facilement oublié.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top