Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.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
Iphone 图像无法显示_Iphone_Uiimageview - Fatal编程技术网

Iphone 图像无法显示

Iphone 图像无法显示,iphone,uiimageview,Iphone,Uiimageview,我需要帮助解决一个我似乎无法解决的问题 我有一个viewcontroller(view1),我通过演示它来显示它 此视图(视图1)上有一个按钮,选中该按钮后,将显示另一个viewController(视图2)。 视图2有几个按钮,当选择一个按钮时,将打开一个新的viewController(view3) 现在的问题是,当在视图3中选择一个按钮时,我想创建一个UIImageView,它保存在视图1中选择的图像(在视图3中按下的按钮)并显示它 在view3中触发操作时,如何在view1中创建具有指定

我需要帮助解决一个我似乎无法解决的问题

我有一个viewcontroller(view1),我通过演示它来显示它

此视图(视图1)上有一个按钮,选中该按钮后,将显示另一个viewController(视图2)。 视图2有几个按钮,当选择一个按钮时,将打开一个新的viewController(view3)

现在的问题是,当在视图3中选择一个按钮时,我想创建一个UIImageView,它保存在视图1中选择的图像(在视图3中按下的按钮)并显示它

在view3中触发操作时,如何在view1中创建具有指定图像的UIImageView

我当前创建了一个图像,但没有设置为或显示在view1上。我甚至不会显示代码,因为这是一个大失败

谢谢
谢谢

您可以使用以下示例代码进行尝试:


// TestAppDelegate.h

#import <UIKit/UIKit.h>
@interface TestAppDelegate : NSObject{
    UIImage *image;
}
@property (nonatomic, retain) UIImage *image;
@end

// TestAppDelegate.m

#import "TestAppDelegate.h"
@implementation TestAppDelegate
@synthesize image;
------
------
------
@end

// TestViewController.m    // sample code

#import "TestViewController.h"
#import "TestAppDelegate.h"

@implementation TestViewController

-(void)setImage{          // If you want to set an image, you can use this method. if you use like this, you can get this image from any view controller.
    TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.image = self.image;
}

-(void)getImage{          // If you want to get image, you can this method.
    TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
    self.image = appDelegate.image;

}

@end


//TestAppDelegate.h
#进口
@接口TestAppDelegate:NSObject{
UIImage*图像;
}
@属性(非原子,保留)UIImage*image;
@结束
//TestAppDelegate.m
#导入“TestAppDelegate.h”
@实现TestAppDelegate
@合成图像;
------
------
------
@结束
//TestViewController.m//示例代码
#导入“TestViewController.h”
#导入“TestAppDelegate.h”
@TestViewController的实现
-(void)setImage{//如果要设置图像,可以使用此方法。如果这样使用,可以从任何视图控制器获取此图像。
TestAppDelegate*appDelegate=(TestAppDelegate*)[[UIApplication sharedApplication]委托];
appDelegate.image=self.image;
}
-(void)getImage{//如果要获取图像,可以使用此方法。
TestAppDelegate*appDelegate=(TestAppDelegate*)[[UIApplication sharedApplication]委托];
self.image=appDelegate.image;
}
@结束

如果您在TestAppDelegate中设置了一个特定的映像,您可以使用“-(void)getImage”方法从任何视图控制器访问该映像。

根据我之前的回答,只需将“TestAppDelegate”中的UIImage替换为NSMutableDictionary即可

如果您想获得特定的图像,只需使用下面的示例代码


TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
self.image = [appDelegate.imageDictionary valueForKey:@"button2"];

谢谢。我会试试类似的。如果有多个图像呢?因为选择的每个按钮都应该创建一个UIImage并为其设置一个图像。

TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
self.image = [appDelegate.imageDictionary valueForKey:@"button2"];