我正在尝试导航到另一个视图并更改其UI。
我设法访问控制器方法“hideElements”, 但是所有元素都是“NIL”,它不会改变任何东西。
(当我在没有导航的情况下访问ViewController.m时,属性不是NIL)
为什么这样,我该如何解决?
ViewController.m:
doLogin.SetRequestHeader ("referer", "https://dividedsky.herokuapp.com/accounts/login/");
doLogin.SetRequestHeader ("cookie", "csrftoken=" + csrfCookie);
doLogin.SetRequestHeader ("X-CSRFToken", csrfCookie);
ViewController2.h
- (void)hideElements:(NSString *)identifier{
[_agreeButton setHidden:TRUE];
[_noThankButton setHidden:TRUE];
[self cleanButtons];
}
ViewController2.m
#import "ViewController.h"
@property (nonatomic) ViewController *myViewController;
答案 0 :(得分:1)
似乎问题是在您调用hideElements
时尚未创建视图控制器的视图(以及包含插座的子视图)。所以你可以做几件事
1)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSString *identifire = [sender text];
ViewController* vc = (ViewController*)segue.destinationViewController;
vc.view;
[vc hideElements:identifire];
}
2)
ViewController2.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSString *identifire = [sender text];
ViewController* vc = (ViewController*)segue.destinationViewController;
vc.shouldHideElements = YES;
}
ViewController.m
- (void)viewDidLoad {
if (self.shouldHideElements) {
[self hideElements];
}
}