本文介绍了UIButton的addtarget:触摸后没有调用!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,当我按下UIButton时,没有任何内容被调用,它也不会崩溃。

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...");
    }

有人知道为什么?

谢谢!

推荐答案

检查标签的大小,它可以是CGSizeZero,但因为子视图的剪辑是NO默认情况下,按钮是可见的,但不可触摸。

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.

这篇关于UIButton的addtarget:触摸后没有调用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:50