My home page has a toolbar with three buttons home,notification and login. I want notification button show only when user loged In. here is my code
//Parent class
@interface Toolbar : UIViewController {
UIToolbar *toolBar;
UIButton *home;
UIButton *notification;
UIButton *login;
BOOL signIn;
}
@property(nonatomic,assign)BOOL signIn;
@property(nonatomic,retain)UIButton *home;
@property(nonatomic,retain)UIButton *notification;
@property(nonatomic,retain)UIButton *login;
@property(nonatomic,retain)UIToolbar *toolBar;
-(IBAction)Home:(id)sender;
-(IBAction)LogIn:(id)sender;
//Toolbar.m
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
if (!signIn) {
[notification setHidden:YES];
[login setHidden:NO];
}else {
[notification setHidden:NO];
[login setHidden:YES];
}
}
//Child class
@interface LoginScreen : Toolbar{
LoginScreen.m
-(IBAction)SignIn{
if ([emailField.text isEqualToString:@"m"] && [passwordField.text isEqualToString:@"a"]) {
NSLog(@"loggedIN");
signIn=YES;
Home *home=[[Home alloc]initWithNibName:@"Home" bundle:nil];
[self.navigationController pushViewController:home animated:YES];
[home release];
}else {
//other condition
}
}
problem is I am able to to go back to home but signIn condition is not working. please guide me . Thanks..
Use Protocols (delegate mechanism) to send back the value to the parent view controller.
See here for some sample. Also here
You can find many samples for this in every Apple sample application.
I have also give you a Sample Application. Go through that and modify the protocol as per your need
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With