Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在故事板中的两个场景之间传输图像_Ios_Storyboard - Fatal编程技术网

Ios 在故事板中的两个场景之间传输图像

Ios 在故事板中的两个场景之间传输图像,ios,storyboard,Ios,Storyboard,我在主视图控制器中有一个图像,我希望此图像在新视图控制器中显示…我知道如何获取两个场景之间的字符串值,但不知道故事板中的图像…请帮助我 Is it right way to pass UIImage to another controller... if UIImage *img1=[UIImage imageNamed:@"1.jpg"]; and UIImageView is *newimgview for newViewController -(void)prepareForSegu

我在主视图控制器中有一个图像,我希望此图像在新视图控制器中显示…我知道如何获取两个场景之间的字符串值,但不知道故事板中的图像…请帮助我

Is it right way to pass UIImage to another controller...

if UIImage *img1=[UIImage imageNamed:@"1.jpg"]; and UIImageView is *newimgview  for newViewController

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"imageview"])
    {
        newViewController *nvc=segue.destinationViewController;
        nvc.newimgview.image=img1;

    }
}

只需传递
UIImage
指针,就像在
performsguewithidentifier

中传递其他数据(如
NSString
)一样,如果您有图像,您可以在ViewController中调用它,无需传递它

[UIImage imageWithContentsOfFile:filePath];


如果最初没有图像,可以像传递字符串一样传递它的指针。请阅读此处了解更多信息:

您可以将文件路径传递到目标视图控制器,或者如果需要,也可以传递图像。添加此方法并尝试传递图像

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"yourImageTransferSegue"]) {

            YourImageTransferViewController *destViewController = segue.destinationViewController;
            destViewController.imageObject = self.imageToBeTransfered;

    }
}

在YourImageTransferViewController的ViewDidLoad中,或者在任何您想使用的地方,使用图像对象作为self.imageObject是的……最终我得到了它……使用此代码

In case  UIImage *imag1=[UIImage imageNamed:@"some.png"];

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"imageview"])
    {
        newViewController *nvc=segue.destinationViewController;
        nvc.imag2=imag1; //imag2 is UIImage that globally declared in newViewController
    }
}

And in newViewController under ViewDidLoad or wherever u want to use...

self.imageview2.image=imag2;
谢谢大家

In case  UIImage *imag1=[UIImage imageNamed:@"some.png"];

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"imageview"])
    {
        newViewController *nvc=segue.destinationViewController;
        nvc.imag2=imag1; //imag2 is UIImage that globally declared in newViewController
    }
}

And in newViewController under ViewDidLoad or wherever u want to use...

self.imageview2.image=imag2;