0

リストのリストを作成しようとしています...しかし、[listaCidades count]を使用すると、例外がスローされます(長い質問で申し訳ありませんが、このメソッドはすべて質問に関連していることを意味します)

 -(void) preencherCidades  {
for (int iCnt = 0; iCnt < [listaEstados count]; iCnt++) {
    NSString *estado = [listaEstados objectAtIndex:iCnt];
    NSArray *listaNomeCidades = nil;
    NSMutableArray *_listaCidades = [[NSMutableArray alloc]init];
    NSString *path = [[NSBundle mainBundle] pathForResource:estado ofType:@"txt"];
    NSString *file = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
    listaNomeCidades = [[file componentsSeparatedByString:@"\n"]retain];

    for (int iCnt2 = 0; iCnt2 < [listaNomeCidades count]; iCnt2++) {
        NSArray *listaNomesPrefeitos = nil;
        NSArray *listaPartidosPrefeitos = nil;
        NSArray *listaVereadores = nil;

        NSString *pathNomePrefeitos = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"prefeito-nome-%@",[listaNomeCidades objectAtIndex:iCnt2]] ofType:@"txt"];
        NSString *fileNomePrefeitos = [NSString stringWithContentsOfFile:pathNomePrefeitos encoding:NSUTF8StringEncoding error:NULL];
        listaNomesPrefeitos = [[fileNomePrefeitos componentsSeparatedByString:@"\n"]retain];

        NSString *pathPartidoPrefeitos = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"prefeito-partido-%@",[listaNomeCidades objectAtIndex:iCnt2]] ofType:@"txt"];
        NSString *filePartidoPrefeitos = [NSString stringWithContentsOfFile:pathPartidoPrefeitos encoding:NSUTF8StringEncoding error:NULL];
        listaPartidosPrefeitos = [[filePartidoPrefeitos componentsSeparatedByString:@"\n"]retain];

        NSString *pathVereadores = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"vereadores-%@",[listaNomeCidades objectAtIndex:iCnt2]] ofType:@"txt"];

        NSString *fileVereadores = [NSString stringWithContentsOfFile:pathVereadores encoding:NSUTF8StringEncoding error:NULL];
        listaVereadores = [[fileVereadores componentsSeparatedByString:@"\n"]retain];
        Prefeito *prefeito = nil;
        if([listaNomesPrefeitos count] > 0 && [listaPartidosPrefeitos count]>0)
            prefeito = [[Prefeito alloc]initWithNome:[listaNomesPrefeitos objectAtIndex:0] partido:[listaPartidosPrefeitos objectAtIndex:0] id:iCnt2];
        Cidade *cidade = [[Cidade alloc]initWithNome:[listaNomeCidades objectAtIndex:iCnt2] prefeito:prefeito listaVereadores:listaVereadores id:iCnt2];

        [_listaCidades addObject:cidade];

    }
    [listaCidades addObject:_listaCidades];

}
}
4

2 に答える 2

1

あなたの答えを見ると[CidadeisEqualToString:]:インスタンス0x1cec00への認識されないセレクター。それが文字列が期待される唯一のポイントであることがわかりましたが、オブジェクトを返しています。あなたが問題を解決するのは良いことです。ハッピーコーディング。

于 2013-02-19T17:20:54.907 に答える
0

私はこれを解決しました

NSMutableArray *listaCidades2 = (NSMutableArray *)[listaCidades objectAtIndex:indiceEstado];  
Cidade *cidade = (Cidade *)[listaCidades2 objectAtIndex:row];
 return cidade.nome;

それ以外の:

 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

    NSMutableArray *listaCidades2 = (NSMutableArray *)[listaCidades objectAtIndex:indiceEstado]; 
return [listaCidades2 objectAtIndex:row];
 }
于 2013-02-19T17:15:15.177 に答える