私は委任を使用して、ViewController2のUILabelからテキストを変更しようとしています。 ViewController1.hでUILabelのテキストを他のView Controllerから変更する
私が持っている:
@protocol WelcomeDelegate
-(void) updateLabelWithString:(NSString*)string;
@end
@interface ViewController1 : UIViewController
@property (weak, nonatomic) id<WelcomeDelegate>delegate;
インサイドViewController1.m:
- (void)presentWelcomeAlert {
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewController2* contentVC = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2ID"];
[self.delegate updateLabelWithString:[NSString stringWithFormat:@"Welcome to the 11Health Family %@! We are here to accompany and support you through the journey as an ostomate. Our new Hydration Tracker is ready to follow your hydration levels. Tap 'Continue' to begin!", [dcsContext sharedContext].activeParticipant.firstName]];
UIViewController *rootVC = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[rootVC presentViewController:contentVC animated:YES completion:nil];
}
インサイドViewController2.hを私は持っている:のviewDidLoadで
#import "SignInViewController.h"
@interface WelcomePopoverViewController() <UIViewControllerTransitioningDelegate>
{
SignInViewController *signInViewController;
}
:
viewController1 = [[ViewController1 alloc] init];
[viewController1 setDelegate:self];
ViewController2.mで私の方法:
- (void)updateLabelWithString:(NSString *)string {
welcomeLabel.text = string;
}
私の問題は、私が最初のビューコントローラからそれを呼び出す場合でも、上記のメソッドが呼び出さ取得されていないということです。