2017-11-22 1 views
0

UIAlertController에서 UIButton을 추가하고 있지만 이벤트가 발생하지 않았습니다.iOS - UIAlertController에서 UBIlertController의 UIButton이 이벤트를 발생시키지 않습니다.

UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 
[cancelBtn setFrame:CGRectMake((_alertController.view.frame.size.width/2)-30, _alertController.view.frame.size.height-50, 60, 30)]; 
[cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal]; 
[cancelBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 
[cancelBtn setBackgroundColor:[UIColor orangeColor]]; 
[cancelBtn addTarget:self action:@selector(forceFullDismiss_FireDelegate:) forControlEvents:UIControlEventTouchUpInside]; 
cancelBtn.showsTouchWhenHighlighted = YES; 

[_alertController.view setUserInteractionEnabled:YES]; 
[_alertController.view addSubview:cancelBtn]; 

버튼이 강조 표시된 것처럼 보이지만 각각의 이벤트가 실행되지 않습니다.

무엇이 문제입니까?

+0

을 사용할 수 있으며 목표에 대한 오류가 없다? breakpoint는'forceFullDismiss_FireDelegate'에서 멈추지 않습니다. –

+0

오류가 없습니다. 예, 브레이크 포인트가 forceFullDismiss_FireDelegate에서 멈추지 않습니다. – Hassy

답변

1

이것은 UIAlertControllerdocumentation입니다.

UIAlertController 클래스는있는 그대로 사용하도록되어 있으며 서브 클래 싱을 지원하지 않습니다. 이 클래스의보기 계층 구조는 비공개이며 은 수정하면 안됩니다.

당신이 취소 버튼을 추가하려는 경우, 당신은

UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 
    // action on cancel 
}]; 

[_alertController addAction:cancel]; 
관련 문제