0

I'm trying to do a list of lists... but when I use [listaCidades count] ...i'm getting throwing exception (sorry for long question but I mean that all this method is relevant for the question)

 -(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];

}
}
12
  • 1
    Do you alloc/init listCidades anywhere? I see that you do for _listaCidades. Commented Feb 19, 2013 at 16:13
  • 1
    can u tell us what exception you are getting Commented Feb 19, 2013 at 16:13
  • @Joel yes, I did alloc and init in viewWillAppear listaCidades = [[NSMutableArray alloc]init]; Commented Feb 19, 2013 at 16:16
  • 1
    Have you tried using breakpoints to see which line the unrecognized selector is on? Commented Feb 19, 2013 at 16:24
  • 1
    I think you are returning Cidade object in picker view delegate method – pickerView:titleForRow:forComponent: . You should return a string. Commented Feb 19, 2013 at 16:45

2 Answers 2

1

By looking at your answer [Cidade isEqualToString:]:unrecognized selector to instance 0x1cec00. I came to know that that is the only point where string is expected but you are returning Object. Its good that you solve the issue. Happy Coding.

Sign up to request clarification or add additional context in comments.

Comments

0

I solved this with

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

instead of:

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

    NSMutableArray *listaCidades2 = (NSMutableArray *)[listaCidades objectAtIndex:indiceEstado]; 
return [listaCidades2 objectAtIndex:row];
 }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.