2011-04-17 46 views
0

所以这是我的代码有:的UIButton没有收到点击

UIButton *svObjectButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

    svObjectButton.frame = CGRectMake(0, 0, 100, 100); 

    [svObjectButton addTarget:self action:@selector(svObjectTouchUpInside) forControlEvents:UIControlEventTouchUpInside];  
    [svView addSubview:svObjectButton]; 

    UIButton *removeButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    removeButton.frame = CGRectMake(0, 0, 20, 20); 
    [removeButton addTarget:self action:@selector(removeButtonPressed) forControlEvents:UIControlEventTouchUpInside]; 
    [svObjectButton addSubview:removeButton]; 
    [svObjectButton bringSubviewToFront:removeButton]; 

但出于某种原因对removeButton全触控直行通过对svObjectButton。

任何想法?

回答

1

我希望你在另一个大按钮上增加一个小按钮...为了达到这个目的,你可以在svView上添加一个UIView(例如buttonView)到一个UIView(例如buttonView),之后你可以同时添加这两个按钮on buttonView(UIview)。您必须避免

  [svObjectButton addSubview:removeButton]; 
0

为什么removeButton必须是svObjectButton的子视图?

我觉得问题在于UIButton是UIButton的子视图。尝试添加removeButton到svView。