I have a view controller, MainViewController in which I have a UIButton as an IBOutlet that is connected up in Interface Builder
In the header I have
@interface MainViewController : UIViewController
{
SettingsViewController *settingsViewController;
UIButton *leftTextButton;
}
@property (nonatomic, retain) IBOutlet UIButton *leftTextButton;
in the .m I have synthesised the property
@synthesize leftTextButton;
I then add a settings subview as follows
SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController"
bundle:nil];
[self.view.superview addSubview:settingsViewController.view];
Within the SettingsViewController I then try to update the title of the UIButton *leftTextButton in the parent view
[ ((MainViewController*) self.parentViewController).leftTextButton setTitle:@"Ahhhhh !!" forState:UIControlStateNormal];
Although this doesn’t crash it doesn’t work – the title of the button does not change.
Any help would be greatly appreciated
The
parentViewControllerproperty isnilunless the view controller is presented modally, or is under aUINavigationControlleror aUITabBarController.Give your
SettingsViewControlleramainViewControllerproperty:Set it when you create the
SettingsViewController:Then you can use it to update the button title: