简体   繁体   English

Segue在UIwebview中传递uiimage并打开

[英]Segue passing uiimage and open in UIwebview

I would like to passing a uiimage from one view to another view which contains a uiwebview. 我想将一个uiimage从一个视图传递到另一个包含uiwebview的视图。 So that i can allow easy interaction and gestures on the image. 这样我就可以在图像上轻松进行交互和手势。

But i have no idea how to code in the viewdidload method should be used. 但我不知道应该如何在viewdidload方法中使用代码。

Here is my code: 这是我的代码:

//first view
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
 if ([segue.identifier isEqualToString:@"showbig"]) {
        bigpic *image = [segue destinationViewController];
        image.bigpicture1 = set11.image;
}

//new view

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSURL *url = [NSURL URLWithString:bigpicture1];
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
    [self.bigpicture loadRequest:requestURL];


}

In the destinationViewController you should have a property UIImage *imageThatIShouldDisplay 在destinationViewController中,你应该有一个属性UIImage *imageThatIShouldDisplay

In your sourceView controller prepareForSegue method you will have something like this: 在你的sourceView控制器prepareForSegue方法中,你将有这样的东西:

if ([segue.identifier isEqualToString:@"showbig"]) {
        YourDestiantionVC *vc = (YourDestiantionVC*)[segue destinationViewController];
        vc.imageThatIShouldDisplay = set1.image;
}

In your destiantion view controller viewDidLoad method you will have: 在您的destiantion视图控制器viewDidLoad方法中,您将拥有:

if(self.imageThatIShouldDisplay != nil) {
 imageViewThatHandlesImageDisplay.image = self.imageThatIShouldDisplay;
}
else { 
 imageViewThatHandlesImageDisplay.image = [UIImage imageWithName:@"my_image_placeholder.png"]; // in case you want a placeholder.
}

You have to load the image from your bundle to load it into the UIWebView since a UIImage can't be loaded directly into a UIWebView. 您必须从捆绑中加载图像才能将其加载到UIWebView中,因为UIImage无法直接加载到UIWebView中。

Answers 答案

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.bigpicture.image = bigpicture1;

}

as i think 我认为

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM