我創建UIView,然後添加UIButton作爲操作的子視圖,但此操作永遠不會被調用。iPhone 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>
)}
你嘗試過使用viewDidLoad和closeAndBack中的斷點嗎? –
不,我不知道如何使用斷點。你能給我建議如何做到這一點? – CroiOS
只在外側/牆上點擊左側,將創建藍色斷點。然後你可以跨過。在底部會有很多按鈕跨越,步入等...... –