Ich verwende Delegierung, um zu versuchen, den Text von einem UILabel in ViewController2 zu ändern.Ändern von Text auf UILabel von einem anderen View Controller
In ViewController1.h ich habe:
@protocol WelcomeDelegate
-(void) updateLabelWithString:(NSString*)string;
@end
@interface ViewController1 : UIViewController
@property (weak, nonatomic) id<WelcomeDelegate>delegate;
Innen 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];
}
Innen ViewController2.h ich habe:
#import "SignInViewController.h"
@interface WelcomePopoverViewController() <UIViewControllerTransitioningDelegate>
{
SignInViewController *signInViewController;
}
Im viewDidLoad:
viewController1 = [[ViewController1 alloc] init];
[viewController1 setDelegate:self];
Meine Methode in ViewController2.m:
- (void)updateLabelWithString:(NSString *)string {
welcomeLabel.text = string;
}
Mein Problem ist, dass das Verfahren, das oben genannt zu werden, ist nicht einmal, wenn ich es von der ersten View-Controller aufrufen.