问题是当点击按钮时,它没有更新!它不会隐藏或显示代码中写入的对象。我错过了什么?
viewcontroller.h
@interface ViewController : UIViewController {
BOOL clicked1;
BOOL clicked2;
}
@property (strong, nonatomic) IBOutlet UIImageView *buttonbg1;
@property (strong, nonatomic) IBOutlet UIImageView *buttonbg11;
@property (strong, nonatomic) IBOutlet UIImageView *buttonbg111;
@property (strong, nonatomic) IBOutlet UIButton *exaa1;
@property (strong, nonatomic) IBOutlet UIButton *exab2;
- (IBAction)exaa1:(id)sender;
- (IBAction)exab2:(id)sender;
@end
viewcontroller.m
- (IBAction)exaa1:(id)sender {
clicked1 = YES;
}
- (IBAction)exab2:(id)sender {
clicked2 = YES;
}
- (void)example1 {
[_exaa1 setTitle:@"1111" forState:UIControlStateNormal];
[_exab2 setTitle:@"2222" forState:UIControlStateNormal];
if (clicked1) {
_buttonbg111.hidden = NO;
_buttonbg11.hidden = YES;
_buttonbg1.hidden = YES;
NSLog(@"1");
} else if(clicked2) {
_buttonbg11.hidden = NO;
_buttonbg1.hidden = YES;
_buttonbg111.hidden = YES;
NSLog(@"2");
}
}
答案 0 :(得分:0)
*- (IBAction)exaa1:(id)sender {
clicked1 = YES;
[self example1];
}
- (IBAction)exab2:(id)sender {
clicked2 = YES;
[self example1];
}
- (void)example1 {
[_exaa1 setTitle:@"1111" forState:UIControlStateNormal];
[_exab2 setTitle:@"2222" forState:UIControlStateNormal];
if (clicked1) {
_buttonbg111.hidden = NO;
_buttonbg11.hidden = YES;
_buttonbg1.hidden = YES;
NSLog(@"1");
} else if(clicked2) {
_buttonbg11.hidden = NO;
_buttonbg1.hidden = YES;
_buttonbg111.hidden = YES;
NSLog(@"2");
}
}*
答案 1 :(得分:0)
您只是忘记在两个IBActions方法中调用您的方法example1。你只需将[self example1]写入两个IBActions方法。你会得到你的确切输出。
答案 2 :(得分:0)
您忘记在两个按钮IBAction方法中调用example1
方法
答案 3 :(得分:0)
Please refer the following corrected code
- (IBAction)exaa1:(id)sender {
clicked1 = YES;
clicked2 = NO;
[self example1];
}
- (IBAction)exab2:(id)sender {
clicked2 = YES;
clicked1 = NO;
[self example1];
}
- (void)example1 {
[_exaa1 setTitle:@"1111" forState:UIControlStateNormal];
[_exab2 setTitle:@"2222" forState:UIControlStateNormal];
if (clicked1) {
_buttonbg111.hidden = NO;
_buttonbg11.hidden = YES;
_buttonbg1.hidden = YES;
NSLog(@"1");
} else if(clicked2) {
_buttonbg11.hidden = NO;
_buttonbg1.hidden = YES;
_buttonbg111.hidden = YES;
NSLog(@"2");
}
}