UITableView单元格自定义问题cellForRowAtIndexPath
我有一个自定义单元格和一个MutableArray数据,但是当我设置我的MutableArray的一个属性的单元格文本时,应用程序崩溃。你可以帮我吗?UITableView单元格自定义问题cellForRowAtIndexPath
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Cria identificador da célula
static NSString *cellID = @"dadosCell";
//Usa célula customizada da classe ProfissionalCell
ProfissionalCell *cell = (ProfissionalCell *) [self.dadosTableView dequeueReusableCellWithIdentifier:cellID];
//Caso não tenha, aloca uma nova célula
if (cell == nil) {
//Com StyleSubtitle, são mostrados título e descrição
cell = [[[NSBundle mainBundle] loadNibNamed:@"ProfissionalCell" owner:self options:nil] objectAtIndex:0];
}
//Profissional selecionado
NSInteger linha = indexPath.row;
Dados *parametro = [profissionais objectAtIndex:linha];
NSLog(@"Nome= %@", cell.cellNome.text);
NSLog(@"Parametro= %@",[[profissionais objectAtIndex:indexPath.row] objectForKey:@"Nome"]);
//Preenche campos
cell.cellNome.text = parametro.nome;
cell.cellProfissao.text = parametro.profissao;
cell.cellEndereco.text = parametro.endereco;
cell.cellIndicacoes.text = parametro.indicacao;
return cell;
}
的碰撞是发生在行:
cell.cellNome.text = parametro.nome;
而行返回 “Parametro = NULL”:
NSLog(@"Parametro= %@",[[profissionais objectAtIndex:indexPath.row] objectForKey:@"Nome"]);
目的是好的,但我不属性一个细胞层。
EDITED
如果我更换的NSLog与下面的代码:
NSLog(@"Nome= %@", [profissionais objectAtIndex:0]);
结果是:
Nome= {
"2013-12-08 19:35:43" = added;
Chibungo = Nome;
"" = Especialidade;
1 = id;
"Sao Paulo " = Cidade;
"11 9999-9999" = Telefone;
"[email protected]" = Email;
"Av. Paulista, 453" = Endereco;
"Servicos Gerais" = Profissao;
SP = Estado;}
如何属性,只有按键 “诺姆”?
感谢您的帮助...我找到了解决我的问题。例如:“Chibungo”是一个键,“Nome”是一个值,但正确的是“Nome”是一个键,“Chibungo”是一个值。
和代码的权利是:
//Profissional da linha
NSInteger linha = indexPath.row;
NSDictionary *dic = (NSDictionary*)[profissionais objectAtIndex:linha];
//Preenche campos
cell.cellNome.text = [dic objectForKey: @"Nome"];
cell.cellProfissao.text = [dic objectForKey: @"Profissao"];
cell.cellEndereco.text = [dic objectForKey: @"Endereco"];
cell.cellIndicacoes.text = [dic objectForKey: @"Indicacoes"];
return cell;
感谢所有!
我想你还没有初始化mutableArray
请检查: -
NSMutableArray *profissionais=[[NSMutableArray alloc]init];
The class“。h“被初始化为:NSMutableArray * profissionais; @property(nonatomic,retain)NSMutableArray * profissionais; – user3093622
可以检查如下定位问题:
确保profissionais不是零和profissionais.count > = indexPath.row + 1
请确保[profissionais objectAtIndex:indexPath.row]是一本字典,它具有密钥@“Nome”
是的,”profissionais“不是零,它是1个对象,有11个键: [0] - > @” 2013-12-08 19:35:43“:@”added“ [1] - > @”Chibungo“:@”Nome“\t [2] - > @”“:@”Especialidade“\t [3 ] - >(int)1:@“id”\t [4] - > @“Sao Paulo”:@“Cidade”\t [5] - > @“11 9999-9999”:@“Telefone”\t [6] - > @“[email protected]”:@“Email”\t [7] - > @“1”:@“Indicacoes”\t [8] - > @“Av。 Paulista,453“:@”Endereco“\t [9] - > @”Servicos Gerais“:@”Profissao“\t [10] - > @”SP“:@”Estado“ – user3093622
在您的项目中,你应该是一个数组。 – youmingtaiz
从你的崩溃日志中,似乎profissionais包含字典,而不是你想要的Dados实例,所以代码“Dados * parametro = [profissionais objectAtIndex:linha];”将分配一个字典到Dados指针,当你调用parameter.nome时,它会崩溃。 – youmingtaiz
你可以添加崩溃日志吗? – sanjaymathad
当应用程序崩溃时,崩溃日志中的消息是什么? – rickerbh
这是应用程序崩溃时的日志: – user3093622