无法隐藏按钮?

时间:2014-11-05 15:11:23

标签: ios objective-c

我有这个按钮,我设置在程序的开头,现在如果我试图隐藏它或在我设置它之后立即显示它:

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];

1 个答案:

答案 0 :(得分:0)

我看到您通过

使用公共(可能)属性来访问按钮
self.outb

然后设置属性,最后在视图中添加按钮

[self.view addSubview:self.outb];

如果您使用IBOutlet,则上一条消息是多余的。您不需要将按钮添加为子视图,因为它已经添加。删除最后一个笔划,然后重试。

希望它有所帮助!