Xcode – update ViewController label text from different view

You have to implement protocols for that. Follow this:

1) In SettingView.h define protocol like this

 @protocol ViewControllerDelegate

 -(void) updateLabel;

  @end

2) Define property in .h class and synthesis in .m class..

    @property (nonatomic, retain) id <ViewControllerDelegate> viewControllerDelegate;

3) In SettingsView.m IBAction

  -(IBAction)backToMain:(id) sender 
 {
     [viewControllerDelegate updateLabel];
 }

4) In ViewController.h adopt protocol like this

@interface ViewController<ViewControllerDelegate>

5) In viewController.m include this line in viewDidLoad

settingView.viewControllerDelegate=self

Leave a Comment