如何在目标c中的.pch中创建ui警报视图

Aks*_*hay 2 iphone

#define kCustomAlert @"UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert Back" message:msg delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];[alert show];"
Run Code Online (Sandbox Code Playgroud)
  1. 如何在视图控制器类中调用此警报?

PJR*_*PJR 7

在你的pch文件中声明这个宏:

 #define kCustomAlert() [[[UIAlertView alloc] initWithTitle:@"Alert Title" message:@"Alert Message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]
Run Code Online (Sandbox Code Playgroud)

宏调用: kCustomAlert();

带参数的警报宏:

#define kCustomAlertWithParam(title,msg) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]

kCustomAlertWithParam(@"This is Title",@"This is message");
Run Code Online (Sandbox Code Playgroud)

带参数和目标的警报宏(用于:UIAlertView委托方法)

Please set UIAlertViewDelegate for your Controller.

#define kCustomAlertWithParamAndTarget(title,msg,target) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:target cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show]

kCustomAlertWithParamAndTarget(@"This is Title",@"This is message",self);
Run Code Online (Sandbox Code Playgroud)