Spa*_*Dog 13 iphone objective-c ios
我在自定义UIActionSheet类中有这个
if (otherButtonTitles != nil) {
[self addButtonWithTitle:otherButtonTitles];
va_list args;
va_start(args, otherButtonTitles);
NSString * title = nil;
while(title = va_arg(args,NSString*)) { // error here
[self addButtonWithTitle:title];
}
va_end(args);
}
Run Code Online (Sandbox Code Playgroud)
我有这个错误
!使用赋值的结果作为没有括号的条件
指着这条线
while(title = va_arg(args,NSString*)) {
Run Code Online (Sandbox Code Playgroud)
这是为什么?
谢谢.
Jac*_*kin 22
这可能不是你说的错误,这是一个警告.
编译器警告您,当它在条件内时,您应该将括号内的赋值括起来,以避免ol' 赋值 - 当你平均比较错误.
要通过这个相当迂腐的编译器警告,您可以简单地在另一对括号中包围该分配:
while((title = va_arg(args,NSString*))) {
//...
}
Run Code Online (Sandbox Code Playgroud)
它应该是警告而不是错误.它试图警告,如果你正在使用,=
但你的意思==
.
在这种情况下,您没有意义使用,==
因为您va_arg()
多次调用迭代otherButtonTitles
并将其分配给temp var title
,因此只需添加另一组括号.警告将消失.
while((title = va_arg(args,NSString*))) {
Run Code Online (Sandbox Code Playgroud)