您好我在实现tableview中的部分后删除单元格/记录时遇到问题。
参见代码
- (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;
}
细节是我不能使用对象id传递给方法
- (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
}
答案 0 :(得分:1)
我在语言差距方面有点挣扎,但看起来你正试图从一个空的crudAlimento
对象中删除一个对象。您正在创建一个新的:
crudAlimento *deleteAlimento = [[crudAlimento alloc] init]; // this is empty unless you're overriding the init method in crudAlimento
然后从中删除一个项目:
[deleteAlimento deletar:objUsuario]; // deleting an object from an empty source
从外观上看,很难判断你的表的数据源是否可变,但假设它是,我想你需要删除一个子元素sessaoAlimento
(类似于sessaoAlimento[indexPath.section].tipoAlimento[indexPath.row]
)