LoginController
尝试进行简单的登录尝试 - 如果成功,则会在setEmail
中调用leftcontroller
。
调用setEmail
时我需要做的就是隐藏btnLogin
并显示buttonUser
并且我尝试的任何内容都无效。 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;
}
答案 0 :(得分:4)
这条线是可疑的:
btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// ...
[self.view addSubview:btnLogin];
如果您要创建btnLogin
并将其自己添加到self.view
代码中,那么为什么它是一个出口?
@property (nonatomic,strong) IBOutlet UIButton *btnLogin;
插座适用于已经存在的内容,并在 nib 中实例化。因此,在我看来,你可能有两个btnLogin
个对象,其中一个消除了你对另一个的引用。对于其他按钮也一样。
答案 1 :(得分:0)
您没有设置属性,请替换:
btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
使用:
self.btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
并定义您的属性,如:
@property (nonatomic,strong) UIButton *btnLogin;
对buttonUser
执行相同操作。
答案 2 :(得分:0)
设置按钮的hidden
后,您会立即说出
[menuController setRootController:navController animated:YES];}
这表明您正在更改界面。但是,如果您要更改界面,是否可以确定您的按钮是否已更改?我不知道你在这里做什么,但也许你的按钮不再在界面中了。也许您在界面中看到的是一组不同的按钮。