Reputation: 2207
I have two classes in my app, GHHaiku
(a subclass of NSObject
) and GHViewController
, which imports GHHaiku
. In GHViewController
I've instantiated GHHaiku
like so:
@property (nonatomic, strong) GHHaiku *ghhaiku;
So when I need to call a method from GHHaiku
in GHViewController
, I can do [self.ghhaiku callThisMethod];
However, I can't figure out what to do if GHHaiku
needs information from GHViewController
. There's a UISegmentedControl
in GHViewController
, for example, and there's a method in GHHaiku
that needs to know which segment of the UISegmentedControl
has been chosen. How do I get it this information? I suppose I could create an int
property in GHHaiku
and then, in GHViewController
, assign the value of the UISegmentedControl
to that property, but that seems cumbersome and I can't imagine there's not a more elegant way to do it.
So what should I do?
(I suspect that Refer to a main view controller property by another class might answer my question but I'm not quite advanced enough to understand the answer given.)
Upvotes: 0
Views: 33
Reputation: 9185
This is an architectural issue that could benefit from think about separation of concerns and more clearly breaking things down roughly along MVC (model/view/controller) lines. See this on MVC competency in Cocoa.
Is GHHaiku
a model object? If so, then it shouldn't really 'know' about things going on in the view layer.
Upvotes: 1