在UIViewController中,tempview2根本没有出现.只有tempview出现了.
-(id) init:(NSData*) imageData
{
if ((self = [super init])) {
tempimage= [[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pic1" ofType:@"png"]] autorelease];
tempview=[[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[tempview setImage:tempimage];
[self.view addsubview tempview];
}
return self;
}
-(void) viewdidload{
tempimage2= [[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pic2" ofType:@"png"]] autorelease];
tempview2=[[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[tempview2 setImage:tempimage2];
[self.view addsubview tempview2];
}
如果我这样做,那么一切都很好,
-(id) init:(NSData*) imageData
{
if ((self = [super init])) {
tempimage= [[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pic1" ofType:@"png"]] autorelease];
tempview=[[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[tempview setImage:tempimage];
[self.view addsubview tempview];
tempimage2= [[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"pic2" ofType:@"png"]] autorelease];
tempview2=[[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
[tempview2 setImage:tempimage2];
[self.view addsubview tempview2];
}
return self;
}
这不是您的问题的直接答案,而是一般的viewcontroller初始化和视图加载的良好实践:
因此,我建议您将视图设置调用移至viewDidLoad,并查看问题是否仍然存在.
祝好运.
| 归档时间: |
|
| 查看次数: |
1841 次 |
| 最近记录: |