I have more page will show the UIAlertController.
So I need write the alert code in a method and class in one page.
I want to use the class and call the method can show the alert on the any Viewcontroller .
How can I write presentviewcontroller in the class.
my header file is below:
#import <Foundation/Foundation.h>
#import "VisionAPI.h"
@interface VisionAPI : NSObject
+(void) showMessageAlert:(NSString *) title andMessage:(NSString*) msg andDoneMsg:(NSString*) done;
@end
My implement file is below:
#import "VisionAPI.h"
#import <UIKit/UIKit.h>
@implementation VisionAPI
+(void) showMessageAlert:(NSString *) title andMessage:(NSString*) msg andDoneMsg:(NSString*) done{
UIAlertController *showMsgAlertController = [UIAlertController alertControllerWithTitle: title message: msg preferredStyle: UIAlertControllerStyleAlert];
UIAlertAction *showMsgAlertControllerOkAction = [UIAlertAction actionWithTitle:done style:UIAlertActionStyleDefault
handler:nil];
[showMsgAlertController addAction:showMsgAlertControllerOkAction];
dispatch_async(dispatch_get_main_queue(), ^{
[self presentViewController:showMsgAlertController animated:YES completion:nil];
});
}
@end
But upper code will show the error in this line:
[self presentViewController:showMsgAlertController animated:YES completion:nil];
How can I presentViewController in the NSObject, or how to fix the problem.