-3

LoginController尝试一个简单的登录尝试——如果成功,它会调用setEmail.leftcontroller

setEmail当被调用时,我需要做的就是隐藏btnLogin并显示,buttonUser而我没有尝试任何工作。s被NSLog调用并且EventsController负载setEmail正常工作 - 它只是不会隐藏和显示按钮。

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;
}
4

3 回答 3

4

这条线是可疑的:

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

如果您是在代码中创建btnLogin并将其添加到self.view自己,那么为什么它是一个出口?

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

出口用于已经存在并在您的nib中实例化的东西。因此,在我看来,您可能有两个btnLogin对象,其中一个对象消除了您对另一个对象的引用。另一个按钮也是如此。

于 2013-04-29T16:50:10.523 回答
0

设置hidden按钮后,您会立即说

[menuController setRootController:navController animated:YES];} 

这表明您正在更改界面。但是如果你在改变界面,你真的能分辨出你的按钮是否改变了吗?我不知道你在这里做什么,但也许你的按钮不再出现在界面中。也许您在界面中看到的是一组不同的按钮。

于 2013-04-29T17:11:32.630 回答
0

您没有设置属性,请替换:

btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

和:

self.btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];

并定义您的财产,例如:

@property (nonatomic,strong) UIButton *btnLogin;

对 做同样的事情buttonUser

于 2013-04-29T16:52:18.053 回答