-1
編譯器標記我的三元運算符,並表示它預期]
而不是kGraySquare
。 我做錯了什麼?使用宏方法調用三元編譯器錯誤
#define kGreenSquare [UIImage [email protected]"distance_on"]
#define kGraySquare [UIImage [email protected]"distance_off"]
@implementation DistanceIndicatorView
{
NSMutableArray<UIImageView*>*items;
}
- (void)drawRect:(CGRect)rect {
items = [[NSMutableArray<UIImageView*> alloc] initWithCapacity:10];
NSInteger offset = 0;
for (int i = 0; i<10; i++){
[items addObject:[[UIImageView alloc] initWithFrame:CGRectMake(offset, 0, 8, 8)]];
[items[i] setImage:_distance<i?kGreenSquare:kGraySquare];
offset += 10;
}
}
你錯過了':'嘗試[UIImage imageNamed:@「distance_on」] – iYoung
這麼愚蠢的錯誤!謝謝你,IYoung! –
如果回答您的問題,您能否將答案標記爲已接受? – iYoung