Objective c iPhone UIButton操作不起作用

Objective c iPhone UIButton操作不起作用,objective-c,uiview,uibutton,Objective C,Uiview,Uibutton,我创建UIView,然后将UIButton添加为带有操作的子视图,但从未调用此操作 有人知道为什么吗 这是我的密码: - (void)viewDidLoad{ UIView *roundResultView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 200, 150)]; UIImageView *_popUpBg = [[UIImageView alloc] initWithImage:[UIImage imageN

我创建UIView,然后将UIButton添加为带有操作的子视图,但从未调用此操作

有人知道为什么吗

这是我的密码:

- (void)viewDidLoad{

    UIView *roundResultView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 200, 150)];
    UIImageView *_popUpBg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"NotificationBg.png"]];
    _popUpBg.frame = CGRectMake(0, 0, roundViewWidth, roundViewHeight);

    UIButton *closeButton = [[UIButton alloc]initWithFrame:CGRectMake(30, 30, 100, 30)];
    [closeButton addTarget:self action:@selector(closeAndBack) forControlEvents:UIControlEventTouchUpInside];
    [closeButton setTitle:@"Back") forState:UIControlStateNormal];
    [roundResultView addSubview:_popUpBg];
    [roundResultView addSubview:closeButton];
    [self.view addSubview:roundResultView];
}


-(void)closeAndBack{
    NSLog(@"closeAndBack"); //never called
}
我已经检查过了:

NSLog(@"%@", [closeButton allControlEvents]);
NSLog(@"%@", [closeButton allTargets]);
它会打印:

... Sedmica[2192:14f03] 64
... Sedmica[2192:14f03] {(
    <ViewController: 0x8631e10>
)}
。。。景天[2192:14f03]64
... 景天属[2192:14f03]{(
)}

用此更新您的代码,并请告诉我:

UIButton *closeButton  = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[closeButton addTarget:self 
                action:@selector(closeAndBack:)
      forControlEvents:UIControlEventTouchDown];
[closeButton setTitle:@"Back"
             forState:UIControlStateNormal];
closeButton.frame = CGRectMake(30.0, 30.0, 100.0, 30.0);
[self.view addSubview:closeButton];


你试过在viewDidLoad和closeAndBack中使用断点吗?没有。我不知道如何使用断点。你能告诉我怎么做吗?在左手边,就在外侧/墙上单击,将创建一个蓝色断点。然后你可以跨过去。在底部会有许多按钮,跨过,进入等…没有点击efect像我的代码。好像有什么东西在那个按钮上,我不能点击它。删除\u popupg子视图和tryNo efect。我甚至尝试使用:[self.view将subview带到front:roundResultView];解决了的。我的另一个UILabel位于UIButton上方,但没有背景色,因此我看不到这个问题。我应该把这个写下来作为答案还是?谢谢您的时间。是的,您可以自己写答案:)
- (IBAction)closeAndBack:(UIButton *)button{
      NSLog(@"Button  clicked.");
}