2011-04-17 78 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。