正如标题所说我试图在UIImageview中显示UIImage,问题是它不会显示。在我展示它之前,我通过另一个视图的segue传递它。当我断点时,我看到UIImage被分配,但没有图片显示,我已经尝试将其设置为静态图片,并且工作正常。
相关代码应该是......
在FirstViewController.m中
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage* img = [info objectForKey:UIImagePickerControllerOriginalImage];
if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
NSLog(@"Bild hämtad!");
[self moveImage];
}
else
{
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), Nil);
}
[picker dismissModalViewControllerAnimated:YES];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
}
- (void)image: (UIImage *)image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo{
if (!error) {
NSLog(@"Bild sparad!");
[self moveImage];
}
else{
NSLog(@"%@",error);
}
}
-(void)moveImage
{
[self performSegueWithIdentifier:@"ImageEdit" sender:self];
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"Bild Flyttad!");
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:self
{
if ([[segue identifier] isEqualToString:@"ImageEdit"])
{
[segue.destinationViewController setMImage:image];
}
}
在ImageEditController.m中
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[imageView setImage:_mImage];
NSLog(@"Bild Visas!");
}
我知道有很多代码,但我认为发布的内容远远超过一点点更好。
答案 0 :(得分:0)
你有没有初始化imageView?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
imageView = [[UIImageView alloc] init];
[imageView setImage:_mImage];
NSLog(@"Bild Visas!");
}
如果它从未被初始化,那么对它的任何函数调用都将无声地失败(在nil指针上调用函数不会做任何事情)。