ios - 在 segue 上移动图像以加载到另一个 UIImageView

标签 ios xcode uiview uiimageview screenshot

我目前正在为 iOS 构建一个应用程序。我正在尝试保存用户当前正在查看的内容,以便我可以为下一个 View 加载它。我知道如何通过

保存图像
 CGSize size = [self.tableView bounds].size;
        UIGraphicsBeginImageContext(size);
        [[self.tableView layer] renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

但是我不知道如何将它们移动到下一个 View Controller 。出于某种原因,上面拒绝将其加载到下一个 View Controller 中的 ImageView 中。

已解决

_incommingImage 是 ImageView 。

我是这样保存的

 NSData *imageData = UIImageJPEGRepresentation(newImage, 1.0);
        NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                               NSUserDomainMask,
                                                               YES);
        NSString *path = [[pathArr objectAtIndex:0]
                          stringByAppendingPathComponent:@"img.data" ];
[imageData writeToFile:path atomically:YES];

然后我用这个加载它。

 NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                           NSUserDomainMask,
                                                           YES);
    NSString *path = [[pathArr objectAtIndex:0]
                      stringByAppendingPathComponent:@"img.data" ];
    NSData *retrievedData = [NSData dataWithContentsOfFile:path];
    _incommingImage.image = [UIImage imageWithData:retrievedData];
       [_incommingImage release];

最佳答案

我同意罗伯特的观点。

FirstViewController.m:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"Your_Identifier"]) {
        SecondViewController *secondVC = segue.destinationViewController;
        secondVC.incommingImage = myImage;
    }
}

SecondViewController.h:

@property (strong, nonatomic) UIImage *incommingImage;

一旦您的 SecondViewController 出现,图像将自动设置为 incommingImage。请务必在 Storyboard 上设置 Segue 的标识符,使其与prepareForSegue 下的标识符相匹配。

关于ios - 在 segue 上移动图像以加载到另一个 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24661381/

相关文章:

c++ - 在 XCode 4.6.2 上使用 cryptopp 静态库在 iOS 应用程序中抛出异常

ios - 锁定屏幕与模态兼容

ios - UIScrollView 不会将点击手势传播给其子级

ios - 存储电话号码的最佳实践 : with or without formatting?

android - 使用 Kotlin 作为 Android 和 iOS 的 RestAPI 解析器

ios - Collection View定位像instagram app swift

ios - Swift Playgrounds 中 Transform 的串联顺序

iPhone 应用程序发送 Facebook 消息或张贴到 friend 的墙上

ios - 在基于页面的应用程序中粘贴到 Web View 上时如何隐藏/取消隐藏 View

xcode - 预期标识符或 '(' - xCode