【发布时间】:2016-01-29 09:31:32
【问题描述】:
我有以下示例代码,用于将警报视图显示为宏
#define SHOW_ALERT(title,msg,del,cancel,other) \
do { \
UIAlertView *_alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:del cancelButtonTitle:cancel otherButtonTitles:other,nil]; \
[_alert show]; \
} while(0);
调用使用
SHOW_ALERT(@"Error!", @"Please Check!", nil, @"Ok", nil)
我正在尝试根据我的字符串传递来处理错误消息
SHOW_ALERT_STATUSCODE(@"404") // give error
这是我尝试过的
#define SHOW_ALERT_STATUSCODE(code) \
do { \
\NSString *errorMsg=@"";\
if([Status_code isEqualtoString:@"404"])\
\{errorMsg=@"Page Not Found";}\
\else if([Status_code isEqualtoString:@"401"])\
\{errorMsg=@"Authentication Failed";}\
\
UIAlertView *_alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:errorMsg delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok",nil]; \
[_alert show]; \
} while(0);
但它给了我以下错误
【问题讨论】:
-
UIAlertView 现在已弃用,请参阅 UIAlertController 代替。
-
帮自己和世界其他人一个忙,创建一个函数或方法。是时候意识到你现在生活在 21 世纪。如果你坚持 do { } while (0) 然后去掉最后的分号。
-
找出我的答案。 . . .如果需要更多帮助,请发表评论。
标签: ios objective-c iphone macros