2014-11-05 131 views
0

我有這個按鈕,在這裏我設置在節目的開始,現在,如果我試圖隱藏或顯示它之後我把他它的工作原理:無法隱藏按鈕?

button.hidden=YES; //set yes or no does works , 

如果我嘗試這樣做,後來,當我點擊它時,它不會消失。

-(void)outb:(UIButton*)button 
{ 
    NSLog(@"%@",button); //has a pointer 
    button.hidden=YES; 
    butotnPointer.hidden=YES; 

不起作用。

這裏的按鈕:

//OUT 
self.outb = [UIButton buttonWithType:UIButtonTypeCustom]; 
self.outb.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter; 
self.outb.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.4]; 
[self.outb addTarget:self action:@selector(outb:)forControlEvents:UIControlEventTouchUpInside]; 
UIImage *outImage = [UIImage imageNamed:@"outButton.png"]; 
[self.outb setImage:outImage forState:UIControlStateNormal]; 
self.outb.frame=CGRectMake(heart.frame.origin.x-bw, startY+(heart.frame.size.width-bh)/2.0, bw, bh); 
self.outb.backgroundColor=[UIColor clearColor]; 
[self.view addSubview:self.outb]; 
+2

檢查你的指針。 Check is self.outb指針與你在IBAction上得到的指針相同,outb:(UIButton *)按鈕。您可能實際上放置了2個按鈕(您的init代碼執行了兩次),然後您隱藏了最上面的按鈕,但仍然可以看到它下面的那個按鈕 – Lefteris 2014-11-05 15:15:38

+0

檢查您的init代碼,它放置的是哪種方法? – mityaika07 2014-11-05 15:18:48

+0

if(button.hidden){butten.hidden = NO} else {button.hidden = YES} – 2014-11-05 15:18:53

回答

0

我看到你使用公共的(可能)屬性訪問按鈕,

self.outb 

然後,設置屬性,最後添加按鈕,您的看法

[self.view addSubview:self.outb]; 

如果使用IBOutlet,則最後的消息是多餘的。您不需要將按鈕添加爲子視圖,因爲它已被添加。刪除最後一筆並再試一次。

希望它有幫助!