2013-12-12 119 views
0

我有一個自定義單元格和一個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;} 

如何屬性,只有按鍵 「諾姆」?

+2

你可以添加崩潰日誌嗎? – sanjaymathad

+0

當應用程序崩潰時,崩潰日誌中的消息是什麼? – rickerbh

+0

這是應用程序崩潰時的日誌: – user3093622

回答

0

感謝您的幫助...我找到了解決我的問題。例如:「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; 

感謝所有!

0

我想你還沒有初始化mutableArray請檢查: -

NSMutableArray *profissionais=[[NSMutableArray alloc]init]; 
+0

The class「。h「被初始化爲:NSMutableArray * profissionais; @property(nonatomic,retain)NSMutableArray * profissionais; – user3093622

0

可以檢查如下定位問題:

  1. 確保profissionais不是零和profissionais.count > = indexPath.row + 1

  2. 請確保[profissionais objectAtIndex:indexPath.row]是一本字典,它具有密鑰@「Nome」

+0

是的,」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

+0

在您的項目中,你應該是一個數組。 – youmingtaiz

+0

從你的崩潰日誌中,似乎profissionais包含字典,而不是你想要的Dados實例,所以代碼「Dados * parametro = [profissionais objectAtIndex:linha];」將分配一個字典到Dados指針,當你調用parameter.nome時,它會崩潰。 – youmingtaiz