NSMutableArray does not add an object! (using addObject: and addObjectsFromArray)

(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 in this file header as:

 NSMutableArray *arquivos; 

[abre abreBrowser] really returns a NSArray .

My problem is [arquivos addObjectsFromArray:arquivosRecebe]; does not work. I also tried addObject and it gives me the same result, i.e. Nothing.

When I feed arquivos as follows:

 arquivos = [abre abreBrowser]; 

it works. But when I do [arquivos addObject:Object] or [arquivos addObjectsFromArray:NSArray] , it does not pass my arquivos NSMutableArray .

Can someone tell me what I'm doing wrong?

+6
source share
2 answers

It looks like you do not allocate arquivos anywhere in the initialization of your object before sending it the addObjectsFromArray message.

+18
source

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

Also, it seems you should switch these statements?

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

For this:

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

Source: https://habr.com/ru/post/888161/


All Articles