UIImage不会显示
问题描述:
我需要帮助,我无法解决问题。UIImage不会显示
我有一个viewcontroller(view1),我通过提出它显示。
这个视图(视图1)上有一个按钮,当它被选中时,会呈现另一个视图控制器(视图2)。 视图2有几个按钮,当选择一个按钮时,它将打开一个新的viewController(view3)。
现在的事情是,当在视图3中选择一个按钮时,我想创建一个UIImageView,它保存View1中被选中的图像(view3中按下的按钮)并显示它。
如何在view3中触发操作时在view1中使用指定的图像创建UIImageView?
我目前正在创建一个图像,但没有设置或在view1上显示。我甚至不会显示代码,因为这是一个很大的失败。
感谢 感谢
答
从我以前的答案,只是用的NSMutableDictionary取代的UIImage在“TestAppDelegate”
UIImage *img1 = [UIImage imageNamed:@"image1.png"];
UIImage *img2 = [UIImage imageNamed:@"image2.png"];
UIImage *img3 = [UIImage imageNamed:@"image3.png"];
[imageDictionary setObject:img1 forKey:@"button1"];
[imageDictionary setObject:img2 forKey:@"button2"];
[imageDictionary setObject:img3 forKey:@"button3"];
,如果你想要得到的特定图像,只需使用下面的示例代码。
TestAppDelegate *appDelegate = (TestAppDelegate*)[[UIApplication sharedApplication] delegate];
self.image = [appDelegate.imageDictionary valueForKey:@"button2"];
答
你可以用下面的示例代码尝试:
// 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特定的图像,您可以使用“任何视图控制器访问图像 - (空) getImage“方法。
非常感谢。我会尝试类似的东西。怎么样有多个图像,每个选择的按钮应该创建一个UIImage并为其设置一个图像。 – jarryd 2010-10-19 16:44:29