Changer l'label d'une vue différente

C'est principalement une question de délégation parce que j'apprends toujours et je ne comprends pas. Je ne sais pas comment créer le délégué dont j'ai besoin.

Je sais que des questions similaires ont été posées, mais les solutions ne m'aident pas. Comment puis-je changer le text d'une label sur View 1 avec le contenu d'un UITextField de View 2?

Merci!

Dans cet extrait de code, ChildViewController est votre View2 et ParentViewController est votre View1.

Dans votre file ChildViewController.h:

@protocol ChildViewControllerDelegate <NSObject> - (void)parentMethodThatChildCanCall:(NSSsortingng *)ssortingng; //pass back the ssortingng value from your textfield @end @interface ChildViewController : UIViewController { @property (weak, nonatomic) IBOutlet UITextField *myTextField; } @property (assign) id <ChildViewControllerDelegate> delegate; 

Dans votre file ChildViewController.m:

 @implementation ChildViewController @synthesize delegate; // Some where in your ChildViewController.m file // to call parent method: //  [self.delegate parentMethodThatChildCanCall:myTextField.text]; 

Dans le file ParentViewController.h:

 @interface parentViewController <ChildViewControllerDelegate> { @property (strong, nonatomic) IBOutlet UILabel *myLabel; } 

Dans le file ParentViewController.m:

 //after create instant of your ChildViewController childViewController.delegate = self; - (void) parentMethodThatChildCanCall:(NSSsortingng *)ssortingng { // assign your passed back textfield value to your label here myLabel.text = ssortingng; }