How does one present a UIAlertController from another class?
I want to know how can you capture the action of an "ok" button in a UIAlertController that was created in Class B but presented in Class A.
This is how I call the method that created the Alert on class "ErrorHandler" from ClassA:
ErrorHandler *handler = [[ErrorHandler alloc] init];
[self presentViewController:[handler alertWithInternetErrorCode] animated:YES completion:nil];
And this is the implementation of alertWithInternetErrorCode in the ErrorHandler.m:
- (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;
}
Again, I want to know how to be able to create these kind of objects in other classes and still be able to present them in the class where you call them. That includes capturing their actions. In this case it would be the NSLog action inside the "cancel button". Would it be possible to call even a method instead of the NSLog? Let's say a delegate method and navigate back to the code in Class A?