-1
大家好,我已經實現瞭如下所示的代碼。當我點擊pressdeal按鈕時,圖像沒有出現在屏幕上。我需要做什麼才能使圖像顯示在UIImageView上?如何在屏幕上顯示隨機圖像的代碼?
- (void)viewDidload{
imagesarray = [[NSMutableArray alloc] initWithObjects:@"bg1.png",@"bg2.png",@"back-button.png",@"bluestar.png",nil];
imageOut = [[UIImageView alloc]init];
}
-(IBAction)pressDeal{
index=arc4random()%4;
image=[UIImage imageNamed:[imagesarray objectAtIndex:index]];
NSLog(@"**********2222************%@",imageOut);
[imageOut setImage:image];
NSLog(@"***********333***********%@",imageOut);
}
2012-03-20 16:41:34.135 pocker[1552:f803] **********2222************<UIImageView: 0x6a71000; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x6a73450>>
2012-03-20 16:41:34.179 pocker[1552:f803] ***********333***********<UIImageView: 0x6a71000; frame = (0 0; 0 0); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x6a73450>>
你想要的「viewDidLoad中」不「的viewDidLoad」 - 這樣的錯誤肯定不會幫你(假設這是你的實際代碼,而不僅僅是一個重寫) – 2012-03-20 11:28:46
- (無效)viewDidLoad中{ \t imagesarray = [[NSMutableArray alloc] initWithObjects:@「bg1.png」,@「bg2.png」,@「back-button.png」,@「bluestar.png」,nil]; \t \t imageOut = [[UIImageView alloc] init]; \t [super viewDidLoad]; \t} – laxmanperamalla 2012-03-20 11:32:06
(你也很可能有一些內存泄漏的,但這些都是垂直於你的主要問題) – 2012-03-20 11:32:58