- (void)loadView
{
[super loadView];
arrayOfImages = [[NSMutableArray alloc]initWithObjects:@"11.jpg",@"22.jpg",@"33.jpg", nil];
UIImageView *awesomeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[awesomeView setImage :[UIImage imageNamed:[arrayOfImages objectAtIndex:0]]];
awesomeView.contentMode = UIViewContentModeScaleAspectFit;
[self.view addSubview:awesomeView];
NSLog(@"%@",[arrayOfImages objectAtIndex:0]);
}
When I put the NSMutableArray
in -(void)viewDidLoad
, UIImageView
displays nothing and NSLog
shows NULL. Why is that?
ps. NSMutableArray worked perfectly in -(void)loadView
. I've declared NSMutableArray *arrayOfImage in @interface .h file
The only way that the given could would output "NULL" in this situation is that arrayOfImages
is NULL
by itself.
This is only possible if arrayOfImages
is declared as a weak variable.
But as @maddy pointed out, your code is all wrong: Don't call super, but assign self.view
. Or use viedDidLoad
instead (probably what you want here).