- (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]);
}当我将NSMutableArray放入-(void)viewDidLoad中时,UIImageView不显示任何内容,而NSLog显示为NULL。为什么会这样呢?
ps。NSMutableArray在-(void)loadView工作得很好。我在@interface .h文件中声明了.h *arrayOfImage
发布于 2014-08-18 06:50:59
在这种情况下,给定的输出"NULL“的唯一方法是arrayOfImages本身是NULL。
这只有在arrayOfImages被声明为弱变量时才有可能。
但是,正如@maddy所指出的,您的代码都是错误的:不要调用super,而是分配self.view。或者使用viedDidLoad代替(可能是您在这里想要的)。
https://stackoverflow.com/questions/25356075
复制相似问题