【问题标题】:Passing Image of ImagePickerView in another View Controller在另一个视图控制器中传递 ImagePickerView 的图像
【发布时间】:2013-12-06 15:32:07
【问题描述】:

大家好,我正在使用 imagePickerView 的视图控制器中的每个人

当用户从库中选择一张照片时,我希望所选照片将显示在另一个视图控制器中。

我目前正在使用情节提要,所以我正在使用这种方法:

- (void) imagePickerController : ( UIImagePickerController *) picker didFinishPickingMediaWithInfo : ( NSDictionary *) info {
        
    UIImage * PhotoForEdit = self.FF_image ;
    PhotoForEdit = [info objectForKey : UIImagePickerControllerEditedImage ] ;
    
   FFEditingPhotoPost *VCPhotoEdit = [[FFEditingPhotoPost alloc] initWithImage:PhotoForEdit];
   [self performSegueWithIdentifier:@"immagine"sender:self];  
   [self.navigationController pushViewController:VCPhotoEdit animated:NO];
   [self dismissViewControllerAnimated:YES completion:nil];

}





  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  {
        FFEditingPhotoPost * controller = (FFEditingPhotoPost *)segue.destinationViewController;
        controller.FFOriginalImage = FF_image;
    }

我的问题是我不能使用在视图 CONTROLLR 中选择的情节提要图像接下来...我在哪里做错了?

谢谢大家的建议

编辑:插入应该显示照片的视图控制器

#import "FFEditingPhotoPost.h"
#import "UIImage+Resize.h"

@interface FFEditingPhotoPost ()

@end

@implementation FFEditingPhotoPost
@synthesize FFScrollView;
@synthesize FFImageView;
@synthesize FFOriginalImage;
@synthesize SelectedFoto;
@synthesize SelectedFotoMiniature;



- (id)initWithImage:(UIImage *)image {
    self = [super initWithNibName:nil bundle:nil];
    if (self) {
        if (!image) {
            return nil;
        }

        FFOriginalImage = image;
       // self.fileUploadBackgroundTaskId = UIBackgroundTaskInvalid;
       // self.photoPostBackgroundTaskId = UIBackgroundTaskInvalid;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    FFScrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    FFScrollView.delegate = self;
    FFScrollView.backgroundColor = [UIColor blackColor];
   // self.view = FFScrollView;

    FFImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20.0f, 42.0f, 280.0f, 280.0f)];
    [FFImageView setBackgroundColor:[UIColor blackColor]];
    [FFImageView setImage:FFOriginalImage];
    [FFImageView setContentMode:UIViewContentModeScaleAspectFit];
    FFImageView.layer.masksToBounds = NO;
    FFImageView.layer.shadowRadius = 3.0f;
    FFImageView.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
    FFImageView.layer.shadowOpacity = 0.5f;
    FFImageView.layer.shouldRasterize = YES;


    [FFScrollView setContentSize:CGSizeMake(FFScrollView.bounds.size.width, FFImageView.frame.origin.y + FFImageView.frame.size.height + FFImageView.frame.size.height)];

    [self shouldUploadImage:FFOriginalImage];

}
- (BOOL)shouldUploadImage:(UIImage *)anImage {
    UIImage *resizedImage = [anImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:CGSizeMake(560.0f, 560.0f) interpolationQuality:kCGInterpolationHigh];

    UIImage *thumbnailImage = [anImage thumbnailImage:86.0f transparentBorder:0.0f cornerRadius:10.0f interpolationQuality:kCGInterpolationDefault];

    // JPEG to decrease file size and enable faster uploads & downloads
    NSData *imageData = UIImageJPEGRepresentation(resizedImage, 0.8f);
    NSData *thumbnailImageData = UIImagePNGRepresentation(thumbnailImage);

    if (!imageData || !thumbnailImageData) {
        return NO;
    }

    SelectedFoto = [PFFile fileWithData:imageData];
    SelectedFotoMiniature = [PFFile fileWithData:thumbnailImageData];
       [SelectedFoto saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"Photo uploaded successfully");
            [SelectedFotoMiniature saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
                if (succeeded) {
                    NSLog(@"Thumbnail uploaded successfully");
                }
            }];
        } else {
        }
    }];

    return YES;
}

【问题讨论】:

  • 为什么在推视图控制器的同时执行segue操作?

标签: ios uiviewcontroller uiimage uistoryboardsegue


【解决方案1】:

我认为 PhotoForEdit = [info objectForKey : UIImagePickerControllerEditedImage ] ;应该是 self.FF_image =

编辑-----

您的代码有几处问题。首先,您正在创建 FFEditingPhotoPost 视图控制器的 2 个副本。谁知道哪一个实际上最终排名第一。

如果您设置了故事板转场,则更改您的图像选择器代码以执行转场,如下所示:

- (void) imagePickerController : ( UIImagePickerController *) picker didFinishPickingMediaWithInfo : ( NSDictionary *) info {

    self.FF_image = [info objectForKey : UIImagePickerControllerEditedImage ] ;

   [self performSegueWithIdentifier:@"immagine"sender:self];

}

您的prepareForSegue 代码很好。请注意,我还切换了设置 self.FF_image 属性的代码,因为这是错误的方法。

现在在您的FFEditingPhotoPost 视图控制器中,您不需要initWithImage 方法,只需使用viewWillAppear 方法来设置您的图像。 viewDidLoad 方法在您的 prepareForSegue 之前调用,这意味着在您尝试使用它时 FFOriginalImage 为 nil。

所以像这样使用viewWillAppear

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [FFImageView setImage:FFOriginalImage];
}

【讨论】:

  • 你好,达伦,谢谢你的回复......你的建议似乎奏效了,应用程序没有崩溃,一切都很好,但我仍然没有看到图像通过......我不明白为什么...我通过插入应该显示照片的视图控制器来编辑我的帖子
  • 删除你的 segue 代码。您已经在分配 VC 并推送它,因此也不需要 segue。 segue 还创建了一个 VC,所以你最终得到 2
猜你喜欢
  • 1970-01-01
  • 2015-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多