I have declared a Button in my MainViewController so when a user logs in it needs to show a button using self.mybutton.hidden = FALSE;
but on my ProfileViewController I have the logout button which needs to hide the button again using self.mybutton.hidden = TRUE;
Which is the best way to communicate between views?
NSUserDefaults could be an easy solution for you without too much thought. Save a particular BOOL value (if you insist) into that, then in each view check that value whether you should be hiding or showing that button:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:TRUE forKey:@"checkThisBool"];
If you are using storyboard, you can pass any information under the prepareForSegue function.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:...]) {
MyViewController *controller = (MyViewController *segue.destinationViewController;
controller.myProperty1 = ...;
controller.myProperty2 = ...;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.