2011-09-07 72 views
0

SomeImage是的UIImageView *全局聲明UIImageView.hidden = NO;但圖像不可見?

-(void)InMethodCalledFromViewDidLoad 
{ 
    SomeImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SomeImage.png"]]; 
SomeImage.frame = CGRectMake(0, 640, 1024,110); 
[self.view addSubview:SomeImage]; 
    SomeImage.hidden = YES; 
    [self OneMoreMethod]; 
} 


-(void)OneMoreMethod{ 
SomeImage.hidden = NO;//image becomes visible 

[self SecondMethod]; 
/*but now from this point onwards even if SomeImage.hidden changed to NO then only nummerical value of SomeImage.hidden changes but image itself stays hidden doesnt become visible at all */ 
} 


-(void)SecondMethod 

{ 

int tmp = 0; 
NSArray* PosAndSizeArrForCurrSlot = [[PosAndSizeArr objectAtIndex:SlotId] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]]; 
for(NSString* values in PosAndSizeArrForCurrSlot) 
    PositionAndSize[tmp++] = [values intValue]; 

} 

我不能夠理解爲什麼SomeImage甚至沒有SecondMethod被調用後hiiden屬性設置爲NO後可見。

回答

1

你試圖在什麼樣的設備上顯示圖像?

SomeImage.frame = CGRectMake(0, 640, 1024,110); 

很可能會嘗試在您設備的可見區域外顯示imageview。 另外你應該真的參考本指南:http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml

只有常量和類應該以大寫字母,變量和方法名稱開頭應該以小寫字母開頭。

+0

iPad,它的iPad! 確實以大寫字母開頭的變量名稱引起了這種行爲? – Yadnesh

+0

不,名稱不會導致此行爲。 –

+0

iPad處於橫向模式;-) –

1

這可能是一個「duh」的答案,但似乎總是咬我的屁股,是你的imageview連接到你的.xib?如果插座沒有設置,它將不會收到更改。

+0

不,我根本不使用IB – Yadnesh

0

你可以把一些NSLog放在前面和結尾,這樣你就可以確保代碼執行到你讓圖像可見的地步了嗎?

-(void)OneMoreMethod{ 
    //SomeImage.hidden = NO;//image becomes visible 
    NSLog(@"before SecondMethod");  
    [self SecondMethod]; 
    NSLog(@"after SecondMethod");  
    SomeImage.hidden = NO;//image becomes visible 
    NSLog(@"after hidden = No"); 
} 

我猜的是在[self SecondMethod]中有一些崩潰,那麼永遠不會到SomeImage.hidden = NO;