-3

LoginController attempts a simple login try - if its successful, it calls setEmail in leftcontroller.

All I need to do when setEmail gets called is to hide the btnLogin and show the buttonUser and nothing I try is working. The NSLogs get called and the EventsController loads so setEmail is working - it just won't hide and show the buttons.

leftcontroller.h:

@interface LeftController : UIViewController <UIApplicationDelegate>
{
    IBOutlet UIButton *btnLogin;
    IBOutlet UIButton *buttonUser;
    NSString *setEmail;
}
@property (nonatomic,strong) IBOutlet UIButton *btnLogin;
@property (nonatomic,strong) IBOutlet UIButton *buttonUser;

@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic) NSString *Email;

//-(void) setEmail : (NSString *) Email;

@end

leftcontroller.m:

- (void) setEmail : (NSString * ) Email{
    [buttonUser setTitle:Email forState:UIControlStateNormal];
    //btnLogin.hidden = YES;
    //buttonUser.hidden = NO;
    [btnLogin setHidden:YES];
    [buttonUser setHidden:NO];

    NSLog(@"Set Email Called");
    NSLog(@"email: %@", Email);

    DDMenuController *menuController = (DDMenuController*)((AppDelegate*)[[UIApplication sharedApplication] delegate]).menuController;
    EventsViewController *controller = [[EventsViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];

        [menuController setRootController:navController animated:YES];
} 

-(void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = HEXCOLOR(0x000000);

    btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnLogin.frame = CGRectMake(0, 0, 180.f, 48);
    [btnLogin setTitle:@"Login" forState:UIControlStateNormal];
    [btnLogin addTarget:self action:@selector(LoginPressed)
       forControlEvents:UIControlEventTouchUpInside];
    btnLogin.tag=1;

    btnLogin.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [btnLogin setTitleColor: [UIColor whiteColor] forState:UIControlStateNormal];
    btnLogin.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

    UIImage *btnImage = [UIImage imageNamed:@"nav_top.png"];
    [btnLogin setBackgroundImage:btnImage forState:UIControlStateNormal];
    [self.view addSubview:btnLogin];

    buttonUser = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    buttonUser.frame = CGRectMake(0, 0, 180.f, 48);
    //[buttonUser setTitle:_Email forState:UIControlStateNormal];
    [buttonUser addTarget:self action:@selector(EmailPressed)
         forControlEvents:UIControlEventTouchUpInside];
    buttonUser.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [buttonUser setTitleColor: [UIColor whiteColor] forState:UIControlStateNormal];
    buttonUser.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

    UIImage *btnImage1 = [UIImage imageNamed:@"nav_top.png"];
    [buttonUser setBackgroundImage:btnImage1 forState:UIControlStateNormal];
    [self.view addSubview:buttonUser];
    buttonUser.hidden = YES;
}
GingerHead
  • 8,130
  • 15
  • 59
  • 93
lsiunsuex
  • 480
  • 6
  • 18
  • Is the button an outlet defined in your XIB or that variable in code or both? – Wain Apr 29 '13 at 16:49
  • no xib - I didn't think I needed the IBOutlet - just been trying different things to try to get it to work – lsiunsuex Apr 29 '13 at 17:03
  • http://stackoverflow.com/questions/4498400/cant-programmatically-hide-uibutton-created-with-ib?rq=1 – matt Apr 29 '13 at 17:13
  • Just a note - you don't need to declare backing store variables for properties with any reasonably modern version of Xcode. Also, having a variable called `setEmail` is a bad idea. cf. KVO – Abizern Apr 29 '13 at 17:15

3 Answers3

4

This line is suspect:

btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// ...
[self.view addSubview:btnLogin];

If you are creating btnLogin and adding it to self.view yourself, in code, then why is it an outlet?

@property (nonatomic,strong) IBOutlet UIButton *btnLogin;

An outlet is for something that already exists and is instantiated in your nib. Hence it seems to me that you might have two btnLogin objects, with one of them wiping out your reference to the other. And the same for the other button.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

You are not setting your properties, replace:

btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

with:

self.btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

And define your property like:

@property (nonatomic,strong) UIButton *btnLogin;

Do the same for buttonUser.

Michael Reneer
  • 2,271
  • 1
  • 16
  • 22
0

After setting the hidden of your buttons, you are immediately saying

[menuController setRootController:navController animated:YES];} 

This suggests that you are changing the interface. But if you are changing the interface, can you really tell whether your buttons have changed? I don't know what you're up to here, but perhaps your buttons are no longer in the interface. Maybe what you are seeing in the interface are a different set of buttons.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • The leftcontroller (which is where the buttons are) is apart of https://github.com/devindoty/DDMenuController - a navbar button pulls out the menu, click on login (then login) and and load the events controller - the left controller never gets unloaded - it just hides – lsiunsuex Apr 29 '13 at 17:14
  • The buttons are in the left controller. If the left controller hides, how do you know the buttons are not changing? You can't see them any more. – matt Apr 29 '13 at 17:15
  • Think the facebook ios app - the menu pulls out on click of the nav bar button - so after i hit login, i hit that nav bar button again and the login button hasen't become hidden – lsiunsuex Apr 29 '13 at 17:18