2013-04-28 239 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

相關問題