2013-04-02 38 views
0

我具有被一個的CGRect幀錯誤屬性

h文件內創建圖像的陣列:

NSMutableArray *imageArray; 

.m文件:

myImage = [[UIImageView alloc] initWithFrame:myImageRect]; 
[imageArray addObject:myImage]; 

如果我直接從myImage變量調用框架,我會得到正確的值:

NSLog(@"Frame x:%f y:%f w:%f h:%f", myImage.frame.origin.x, myImage.frame.origin.y, myImage.frame.size.width, myImage.frame.size.height); 

輸出:`幀x:226.000000 Y:226.000000瓦特:226.000000 H:334.000000``

但是,如果我通過陣列調用圖像它給我不正確的值:

UIImageView *anImage = [imageArray objectAtIndex:5];   
NSLog(@"frame x:%f y:%f w:%f h:%f", anImage.frame.origin.x, anImage.frame.origin.y, anImage.frame.size.width, anImage.frame.size.height); 

輸出:frame x:0.000000 y:0.000000 w:0.000000 h:0.000000

我在做什麼錯?

+3

你的Alloc +初始化的imagArray? –

+1

我會在@AnoopVaidya的理論上下注1美元。 – danh

回答

0

,你是什麼洞錯的是陣列

NSMutableArray *imageArray=[[NSMutableArray alloc]initWithCapacity:5]; 

的初始化嘗試

NSMutableArray *imageArray=[[NSMutableArray alloc]initWithCapacity:5]; 
UIImageView * myImage ; 
CGRect myImageRect=CGRectMake(10, 10, 10, 10); 

for (int i=0; i<5; i++) { 
    myImage= [[UIImageView alloc] initWithFrame:myImageRect]; 
    [imageArray addObject:myImage]; 

} 
UIImageView *anImage = [imageArray objectAtIndex:3]; 
NSLog(@"%@",NSStringFromCGRect(anImage.frame)); 

結果

2013-04-03 01:10:49.114 TrialsError[95088:11303] {{10, 10}, {10, 10}}