【发布时间】:2014-05-06 17:55:02
【问题描述】:
当我在.h 上定义按钮时,它可以工作,但是当我编写代码时,按钮不起作用。
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *buttonImage = [UIImage imageNamed:@"nl.png"];
//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(230,302,32,32);
[button setImage:buttonImage forState:UIControlStateNormal];
//create a UIBarButtonItem with the button as a custom view
//UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
[button addTarget:self action:@selector(clickActionItem) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)btnClicked
{
[self.button Sethidden:YES]:
self.button.hidden=YES;
_button.hidden=YES;
}
但是不行
【问题讨论】:
-
[self.button Sethidden:YES]:好吧,倒转大写,用“:”代替“;”。请问,你的真实密码是什么?什么时候调用“btnClicked”? -
你的按钮是一个局部变量,你不能通过self.button在其他方法中得到它