编译器标记我的三元运算符并表示它期望]
而不是kGraySquare
。
我做错了什么?
#define kGreenSquare [UIImage imageNamed@"distance_on"]
#define kGraySquare [UIImage imageNamed@"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;
}
}
答案 0 :(得分:4)
您错过了:
添加冒号(:)&amp;如下更新
#define kGreenSquare [UIImage imageNamed:@"distance_on"]
#define kGraySquare [UIImage imageNamed:@"distance_off"]
这样可以正常工作。