-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