我创建 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>
)}