【发布时间】:2016-12-10 19:33:35
【问题描述】:
如何呈现另一个类的 UIAlertController?
我想知道如何在 UIAlertController 中捕获“确定”按钮的操作,该控制器是在 B 类中创建但在 A 类中呈现的。
这就是我如何从 ClassA 调用在类“ErrorHandler”上创建警报的方法:
ErrorHandler *handler = [[ErrorHandler alloc] init];
[self presentViewController:[handler alertWithInternetErrorCode] animated:YES completion:nil];
这是ErrorHandler.m中alertWithInternetErrorCode的实现:
- (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 类中的代码?
【问题讨论】:
-
传递一个视图控制器,例如:- (void)presentAlertWithInternetErrorCodeOnController:(UIViewController *)controller
标签: ios objective-c methods delegates uialertcontroller