【发布时间】:2017-06-26 19:04:55
【问题描述】:
我正在使用委托来尝试从 ViewController2 中的 UILabel 更改文本。
在 ViewController1.h 我有:
@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 里面我有:
#import "SignInViewController.h"
@interface WelcomePopoverViewController () <UIViewControllerTransitioningDelegate>
{
SignInViewController *signInViewController;
}
在viewDidLoad中:
viewController1 = [[ViewController1 alloc] init];
[viewController1 setDelegate:self];
我在 ViewController2.m 中的方法:
- (void)updateLabelWithString:(NSString *)string {
welcomeLabel.text = string;
}
我的问题是即使我从第一个视图控制器调用上面的方法也没有被调用。
【问题讨论】:
标签: ios objective-c xcode