2

正如标题所说,我试图在 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!");
}

我知道有很多代码,但我认为发布比发布少更好。

4

1 回答 1

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 指针上调用函数什么都不做)。

于 2012-05-21T19:58:15.050 回答