editingStyleForRowAtIndexPath não está sendo chamado (Assim, um botão excluir está aparecendo)
-
19-09-2019 - |
Pergunta
Eu estou brincando com UITableViewCells móveis, e por qualquer motivo,
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingstyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone; //<-- bp set on it
}
não está sendo chamado (eu definir um ponto de interrupção sobre ele) - portanto, a tabela está mostrando a opção de exclusão, mas eu não quero isso. Aqui está a minha aplicação:
@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
Não há avisos em tempo de compilação.
Obrigado!
Solução
Tente capitalizando o nome do método corretamente
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
Isso é com o S
em editingStyleForRowAtIndexPath
capitalizados. seletores ObjC são maiúsculas de minúsculas. A exibição de tabela não acho que é responde delegado para o método que você está tentando fornecer um valor de retorno para.
Outras dicas
Você precisa definir a seleção múltipla para NO no modo de edição
self.tableview.allowsMultipleSelectionDuringEditing = NO;
Outra razão pode ser que você também precisa implementar
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
Outra razão para editingStyleForRowAtIndexPath (e outros delegados) não sendo chamado é se o controle não tê-lo da tomada delegado ligado ao dono do arquivo.
Sim, isso é óbvio, mas é facilmente esquecido.