6
(IBAction)adicionarPastas:(id)sender {

    AbreBrowser *abre = [[AbreBrowser alloc] init];

    NSMutableArray *arquivosRecebe = [[NSMutableArray alloc] initWithArray:[abre abreBrowser]];
    [abre release];

    [arquivos addObjectsFromArray:arquivosRecebe];    
    [arquivosTableView reloadData];

    [arquivosTableView setDataSource:self];
}

Well, arquivos is declared on this files header as:

NSMutableArray *arquivos;

[abre abreBrowser] indeed returns a NSArray.

My problem is [arquivos addObjectsFromArray:arquivosRecebe]; doesn't work. I also tried addObject and it gives me the same result, i.e. nothing.

When I feed arquivos like this:

arquivos = [abre abreBrowser]; 

it works. But when I do a [arquivos addObject:Object] or [arquivos addObjectsFromArray:NSArray] it doesnt feeds my NSMutableArray arquivos.

Can someone tell me what I'm doing wrong?

2 Answers 2

18

It appears that you are not allocating arquivos anywhere in your object's initialization before actually sending the addObjectsFromArray message to it.

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

3 Comments

oh my god, you`re right, thank you. after allocating it, it worked. how could i miss that???? i deserve a slap on my face. god....
:-) The answer was in your question itself; you said - "when i feed arquivos like 'arquivos = [abre abreBrowser];' it works."
This prevented me from banging my head into a wall for very long!
0

So why don't you use that which works? arquivos = [abre abreBrowser];

Also, it seems you should switch these statements?

   [arquivosTableView reloadData];
   [arquivosTableView setDataSource:self];

To this:

   [arquivosTableView setDataSource:self];
   [arquivosTableView reloadData];

1 Comment

i didnt use the way that works because i want to keep adding objects into the NSMutableArray, and using the way that works was not possible. Thanks for your help too, the previous answer solved my problem, but i`ll take your sugestion and invert those lines.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.