다른 클래스의 UIAlertController를 어떻게 표시합니까? 난 당신이 클래스 B에서 만든하지만 클래스 A에 발표 된 UIAlertController에 "OK"버튼의 동작을 캡처 할 수있는 방법을 알고 싶어요 Objective-C의 다른 클래스에서 현재 "컨트롤러"
는이 내가 경고를 생성 한 메소드를 호출하는 방법입니다
ErrorHandler *handler = [[ErrorHandler alloc] init];
[self presentViewController:[handler alertWithInternetErrorCode] animated:YES completion:nil];
그리고 이것은 ErrorHandler.m에서 alertWithInternetErrorCode의 구현 : :를 ClassA에서 클래스 "ErrorHandler를"다시
- (UIAlertController *)alertWithInternetErrorCode{
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:@"Error"
message:@"No internet conneciton"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction * cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {
NSLog(@"cancelled");
}];
[alert addAction:cancel];
return alert;
}
, 내가 원하는 다른 클래스에서 이러한 종류의 객체를 생성 할 수있는 방법을 알고, 호출 한 클래스에서 계속 객체를 표현할 수 있어야합니다. 그것은 그들의 행동을 포착하는 것을 포함합니다. 이 경우 "취소 버튼"안에 NSLog 조치가 있습니다. NSLog 대신 메서드를 호출 할 수 있습니까? 델리게이트 메서드를 호출하고 클래스 A의 코드로 돌아가 보자.
패스가보기 컨트롤러 같은 : - (무효) presentAlertWithInternetErrorCodeOnController : (UIViewController에 *) 컨트롤러 –