我有以下课程
#import <UIKit/UIKit.h>
@interface UIImageViewInfo : UIImageView
@property(nonatomic,strong) NSString* colorInfo;
@end
在 function1 中创建 UIImageViewInfo 时(下面的帖子)我得到了正确的结果
“UIImageViewInfo:0x1d8acd60;baseClass = UIImageView;帧 =(0 0;20 20);不透明 = NO;userInteractionEnabled = NO;标签 = 2000;层 = CALayer:0x1d8a0560>>”
但是在function2中创建一些东西(发布在下面)我得到了-(null)
UIImageViewInfo: 0x8372c40; 基类 = UIImageView; 帧 = (0 0; 20 20); 阿尔法 = 0; 隐藏=是;不透明=否;用户交互启用 = 否;标签 = 2000; 层 = CALayer: 0x8380090>> - (null)
为什么有 - (null) ?
提前感谢
PS> 这里更多来自我的代码
-(void)function1{
UIImageViewInfo *image;
self.solutionPinSlots = [[NSMutableArray alloc] init];
for (int i=0; i<M; i++) {
image = [[UIImageViewInfo alloc] initWithImage:[UIImage imageNamed:@"solutionPeg@2x.png"]];
image.translatesAutoresizingMaskIntoConstraints=NO;
image.hidden=YES;
image.alpha = 0;
image.colorInfo = @"clear";
image.tag = 2000*(self.brainController.slotsIndex+1) +i;
[self.solutionPinSlots addObject:image];
[self.view addSubview:(UIImageViewInfo *)self.solutionPinSlots[i]];
}
NSLog(@"solutionSlots: %@",self.solutionPinSlots);
__block int counter = 0;
[self.brainController.solution enumerateObjectsUsingBlock:^(NSString *peg, NSUInteger idx, BOOL *stop){
for (int i=0;i<M;i++) {
if ([self.brainController.slots[self.brainController.slotsIndex][i] isEqual:peg]) {
if (i==idx) {
((UIImageViewInfo *) self.solutionPinSlots[counter]).backgroundColor = [UIColor whiteColor];
((UIImageViewInfo *) self.solutionPinSlots[counter]).colorInfo=@"white";
}else{
((UIImageViewInfo *) self.solutionPinSlots[counter]).backgroundColor = [UIColor blackColor];
((UIImageViewInfo *) self.solutionPinSlots[counter]).colorInfo=@"black";}
((UIImageViewInfo *) self.solutionPinSlots[counter]).hidden=NO;
((UIImageViewInfo *) self.solutionPinSlots[counter++]).alpha=1;
}
}
}];
[self.solutionPinSlots shuffle];
[self updateSolutionPinSlots];
}
-(void)function2{
NSString *obj;
for (int idx=0; idx< M;idx++ ) {
UIImageViewInfo *image = [[UIImageViewInfo alloc] initWithImage:[UIImage imageNamed:@"solutionPeg@2x.png"]];
image.translatesAutoresizingMaskIntoConstraints=NO;
obj = (NSString *) [self.solutionPinSlots objectAtIndex:idx];
image.tag=2000*(self.brainController.slotsIndex+1)+idx;
image.hidden=NO;
image.alpha = 1;
if ([obj isEqualToString:@"clear"]) {
image.hidden=YES;
image.alpha = 0;
image.colorInfo=@"clear";
image.backgroundColor=[UIColor clearColor];
}else if ([obj isEqualToString:@"white"]){
image.colorInfo=@"white";
image.backgroundColor=[UIColor whiteColor];
}else if ([obj isEqualToString:@"black"]){
image.colorInfo=@"black";
image.backgroundColor=[UIColor blackColor];
}else{
NSLog(@"Something is Wrong!!!");
}
[self.solutionPinSlots replaceObjectAtIndex:idx withObject:image];
[self.view addSubview:image];
}
}