开发者

UIButton's addtarget: not called after touch it!

I have the following code, and when i press the UIButton,开发者_如何学运维 nothing is called, and it doesn't crash.

    calloutButton = [[UIView alloc] initWithFrame:CGRectMake(left_width2*2-3, 5, 230, 230)];
    UIButton *buttongo= [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    buttongo.frame=CGRectMake(0, -1, 25, 25);
    [buttongo addTarget:self action:@selector(buttonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [calloutButton addSubview:buttongo];

    [label addSubview:calloutButton];




    -(IBAction)buttonEvent:(id)sender 
    {
          NSLog(@"Hello...");
    }

Someone Knows why?

Thanks!


Check the size of the label, it can be CGSizeZero, but because the clipping of subviews is NO by default so the button is visible, but it isn't touchable.


Make sure you not have

@property IBOutlet UIButton *yourButton;

with same name with

@implementation {
    UIButton *_yourButton;
}

I had such problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜