我尝试制作一个简单的宏来在iOS中创建和显示一个简单的“确定”对话框:
#define ALERT_DIALOG(title,message) \
do\
{\
UIAlertView *alert_Dialog = [[UIAlertView alloc] initWithTitle:(title) message:(message) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];\
[alert_Dialog show];\
} while ( 0 )
如果我尝试在我的代码中使用它:
ALERT_DIALOG(@"Warning", @"Message");
我收到错误:
解析问题。预期为']'
并且错误似乎指向@
之前的第二个"Message"
。
但是,如果我只是复制粘贴宏,则不会出现此错误:
NSString *title = @"Warning";
NSString *message = @"Message";
do
{
UIAlertView *alert_Dialog = [[UIAlertView alloc] initWithTitle:(title) message:(message) delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert_Dialog show];
} while ( 0 );
是否有一些反对在宏中使用Objective-c构造的东西?还是其他?
您的宏的问题是,message
中的[[[[bothings