leedream
leedream

Reputation: 559

Do not delete cell using the TableView section

Hello I'm having trouble deleting a cell / record after it implemented the section in tableview.

See the code

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"celula";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    alimento *p = [sessaoAlimento objectAtIndex:indexPath.section];
    crudAlimento *obj = [[crudAlimento alloc] init];
    NSArray *arrayAlime = [obj listarAlimentoSessao:[p tipoAlimento] filtro:srBar.text];
    alimento *objAlimento = [arrayAlime objectAtIndex:indexPath.row];

    NSString *registro = [NSString stringWithFormat:@"%@ - %@", [objAlimento alimentoid], [objAlimento nomeAlimento]];

    [[cell textLabel]setText:registro];

    return cell; 
}

detail is that I can not use object id to pass to the method

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    crudAlimento *deleteAlimento = [[crudAlimento alloc] init];
    alimento *objUsuario = [arrayAlimento objectAtIndex:indexPath.row];
    [deleteAlimento deletar:objUsuario];
    [self carregaListaSessao:@""];//com sessao
}

Upvotes: 0

Views: 34

Answers (1)

Stonz2
Stonz2

Reputation: 6396

I'm struggling a little with the language gap, but it looks like you are trying to delete an object from an empty crudAlimento object. You are creating a new one:

crudAlimento *deleteAlimento = [[crudAlimento alloc] init];  // this is empty unless you're overriding the init method in crudAlimento

And then deleting an item from it:

[deleteAlimento deletar:objUsuario]; // deleting an object from an empty source

From the looks of things, it's hard to tell if your data source for your table is mutable, but assuming it is, I think you need to remove a sub-element of sessaoAlimento (something like sessaoAlimento[indexPath.section].tipoAlimento[indexPath.row])

Upvotes: 1

Related Questions