user1396952
user1396952

Reputation: 1

Objective C access variable from different view controller

I am using a utility application in storyboard. I also created a third viewcontroller, which is accessed through a segue from the flipsideviewcontroller. I want to add a value in the third viewcontroller to an NSMutableArray that exists in the mainviewcontroller. I have played around with "delegation", but I have not been able to get it to work. My question is, how do I access my array that is defined in the mainviewcontroller from the third viewcontroller? Thanks.

Upvotes: 0

Views: 148

Answers (1)

Cthutu
Cthutu

Reputation: 8907

When you create the 3rd view controller you can set a weak property that points to that array. Or you can define a delegate protocol that the 3rd view controller has a reference to, but the main view controller implements:

my3rdviewcontroller.delegate = mainViewController;

then in my3rdviewcontroller:

[self.delegate addValue:myValue];

and of course mainViewController implements the addValue: message.

Upvotes: 1

Related Questions