2013-04-28 247 views
-3

结束时,我有下面的类为什么 - (空)在我的对象

#import <UIKit/UIKit.h> 

@interface UIImageViewInfo : UIImageView 
@property(nonatomic,strong) NSString* colorInfo; 
@end 

在功能1(后下)创建UIImageViewInfo当我得到正确的结果

“UIImageViewInfo :0x1d8acd60;基类=的UIImageView;帧=(0 0; 20 20);不透明= NO; userInteractionEnabled = NO;标记= 2000;层= 的CALayer:0x1d8a0560 >>”

但创造的函数2东西(贴在下面),我得到的 - (空)

UIImageViewInfo:0x8372c40; baseClass = UIImageView; frame =(0 0; 20 20); alpha = 0;隐藏= YES; opaque = NO; userInteractionEnabled = 否; tag = 2000; layer = CALayer:0x8380090 >> - (null)

为什么会有 - (null)?

Thanx提前

PS>这里是我的代码

-(void)function1{ 
UIImageViewInfo *image; 
self.solutionPinSlots = [[NSMutableArray alloc] init]; 

for (int i=0; i<M; i++) { 
    image = [[UIImageViewInfo alloc] initWithImage:[UIImage imageNamed:@"[email protected]"]]; 
    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])[email protected]"white"; 
      }else{ 
       ((UIImageViewInfo *) self.solutionPinSlots[counter]).backgroundColor = [UIColor blackColor]; 
       ((UIImageViewInfo *) self.solutionPinSlots[counter])[email protected]"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:@"[email protected]"]]; 
    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; 
     [email protected]"clear"; 
     image.backgroundColor=[UIColor clearColor]; 
    }else if ([obj isEqualToString:@"white"]){ 
     [email protected]"white"; 
     image.backgroundColor=[UIColor whiteColor]; 
    }else if ([obj isEqualToString:@"black"]){ 
     [email protected]"black"; 
     image.backgroundColor=[UIColor blackColor]; 
    }else{ 
     NSLog(@"Something is Wrong!!!"); 
    } 

    [self.solutionPinSlots replaceObjectAtIndex:idx withObject:image]; 

    [self.view addSubview:image]; 
} 

}

+0

发布您的描述方法的实现。 – bbum 2013-04-28 18:49:06

+0

我没有一个,我依靠在我的情况下是UIImageView的超类。 – mjeragh 2013-04-29 04:52:36

回答

1

更因为你的NSLog调用(你不这样做显示)是要求第二个对象,第二个对象是空的。

+0

Thankx为您的快速回答,但我没有使用NSLog,我正在使用PO – mjeragh 2013-04-28 18:28:55

+0

从lldb控制台打印此信息。然后,如bbum所述,这是您类的“描述”方法的一个工件。但是答案仍然是一样的:'description'方法要求并试图表示一些空的第二个对象。 – matt 2013-04-28 18:34:15

2

没关系。它来自UIView的description方法,这是相当复杂的,并转储了一堆关于视图的信息。其中一个条件被您的配置绊倒,导致(null)结束。

安全无视。

UIKit中没有 UIImageViewInfo类,所以实现必须在您的项目中。在此实施,有可能是一个 description方法来实现这样的:

- (NSString*)description { 
    .... 
    return [NSString stringWithFormat:@"UIImageViewInfo:%p; %@ - %@", self, [super description], someInstanceVariableThatHappensToBeNil]]; 
} 

只有你description可能更复杂,因为有时有时做这一点,输出。

当子类化UIKit时,不应该在 UI前缀类。

+0

UIImageViewInfo是我的类不在UIKit中。我将发布我的两个函数 – mjeragh 2013-04-28 18:40:47

+1

@mjeragh是的 - 不要以你的类为前缀。保留给苹果公司,它会让你的代码非常困惑别人阅读。显然,这里不是问题,但... – bbum 2013-04-28 18:48:31

+0

你的回答是正确的。我很惊讶为什么他们关闭了这个问题 – mjeragh 2013-04-30 10:00:42

相关问题