2010-10-19 61 views
0

我需要幫助,我無法解決問題。UIImage不會顯示

我有一個viewcontroller(view1),我通過提出它顯示。

這個視圖(視圖1)上有一個按鈕,當它被選中時,會呈現另一個視圖控制器(視圖2)。 視圖2有幾個按鈕,當選擇一個按鈕時,它將打開一個新的viewController(view3)。

現在的事情是,當在視圖3中選擇一個按鈕時,我想創建一個UIImageView,它保存View1中被選中的圖像(view3中按下的按鈕)並顯示它。

如何在view3中觸發操作時在view1中使用指定的圖像創建UIImageView?

我目前正在創建一個圖像,但沒有設置或在view1上顯示。我甚至不會顯示代碼,因爲這是一個很大的失敗。

感謝 感謝

回答

1

從我以前的答案,只是用的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"]; 
0

你可以用下面的示例代碼嘗試:


// 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「方法。

+0

非常感謝。我會嘗試類似的東西。怎麼樣有多個圖像,每個選擇的按鈕應該創建一個UIImage併爲其設置一個圖像。 – jarryd 2010-10-19 16:44:29