我正在使用UIimagepickercontroller浏览或拍摄照片,并将其显示在子视图上。
-(IBAction) getPhoto:(id) sender {
secondView1 = [[secondView alloc]
initWithNibName:@"secondView"
bundle:nil];
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
[self.view addSubview:secondView1.view];
}这在SourceTypeSavedPhotoAlbum上运行良好,但如果我使用相机,则不会显示secudview1.view。相反,它只显示原始视图。
这是我的委托方法:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
secondView1.imageView.image = [info
objectForKey:@"UIImagePickerControllerOriginalImage"];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}谢谢你的帮助!
发布于 2011-12-12 10:37:06
我终于发现我应该这样做:
secondView1 = [[secondView alloc]
initWithNibName:@"secondView"
bundle:nil];
self.view addSubview:secondView1.view];在委托函数中。
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
...
}否则,可能会在图像拾取器完成图像拾取之前调用addsubview。现在更好地了解代码流和委托的功能。
https://stackoverflow.com/questions/8411060
复制相似问题