我試圖從其他viewControllers更改UIImageView
,但我不知道爲什麼圖像不會更改!這裏是我的代碼:從另一個VI控制器更改UIImageView
#import "ViewController.h"
@class ViewController;
@interface CoverGallery : UIViewController {
ViewController *mainViewController;
}
@property (nonatomic,retain) ViewController *mainViewController;
- (IBAction)img1;
.M
- (IBAction)img1 {
mainViewController.coverArt.image = [UIImage imageNamed:@"coverDefault.png"];
[self dismissModalViewControllerAnimated:YES];
}
有一個叫封面藝術在MainViewController一個UIImageView
,感謝
這裏是我的按鈕操作,其視圖之間切換:
ViewController(My First view) .h
@interface ViewController : UIViewController {
ViewController *mainViewController;
}
@property (nonatomic, retain) ViewController *mainViewController;
.m :
@synthesize mainViewController;
- (void) CoverGallery {
CoverGallery *gallery = [[CoverGallery alloc] initWithNibName:@"CoverGallery" bundle:nil];
gallery.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:gallery animated:YES];
//here is the problem, compiler gives me the mainViewController is not the property of CoverGallery
gallery. mainViewController = self;
[gallery release];
}
您是否檢查過[[UIImage imageNamed:@「coverDefault.png」]'是否實際返回有效圖像? – Till 2012-01-06 20:34:52
你在哪裏設置你的'mainViewController'? – 2012-01-06 20:43:05
是設置爲:[gallery.mainViewController = self];在展示圖庫視圖之前。 – 2012-01-06 20:59:04