Reputation: 2724
I know there are similar questions out there, but please consider mine before writing it off as a duplicate.
I have a true/false that the View Controller receives from user input and uses to adjust the selected state of a button, then passes the true/false data to a UIView where a method is run. Once the method is done I would like to return the selected state of the button back to NO, however when I try to tell the UIView to access the ViewControllers button I run into some problems.
Could someone please tell me how I might do this and, if it's not possible, could you outline where I have strayed from the MVC pattern and how I might get back on track?
Upvotes: 1
Views: 346
Reputation: 3423
I would use an NSNotification. Easier to get your head around than delegation if this is all new to you.
register something like this in your parent view controller:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(methodToChangeButtonState) name:@"changeButtonState" object:nil];
and call it at the appropriate time from your child viewcontroller:
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeButtonState" object:nil];
Your methodToChangeButtonState will fire when the notification is posted updating your button state.
Upvotes: 3