谁能告诉我以下原因为何:
if (newEditingMode) {
dayView.dayViewIsInEditingMode = YES;
}
else{
dayView.dayViewIsInEditingMode = NO;
}
但是以下给出了错误
Expression is not assignable
:newEditingMode ? dayView.dayViewIsInEditingMode = YES : dayView.dayViewIsInEditingMode = NO;
最佳答案
您可以使用括号并将其编译。请尝试以下方法。
newEditingMode ? (dayView.dayViewIsInEditingMode = YES) : (dayView.dayViewIsInEditingMode = NO);
但是,您不应该在三元条件本身内部执行赋值。您应该改用它。
dayView.dayViewIsInEditingMode = newEditingMode ? YES : NO;
或者,在这种情况下,您可以完全删除三元,因为它是多余的。
dayView.dayViewIsInEditingMode = newEditingMode;
关于objective-c - 三元条件运算符中的赋值产生 “Expression is not assignable”错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16255601/