简体   繁体   中英

Displaying an image when new view controller appears

I current have two ViewControllers: SliderGaloreController and SliderGaloreFlipsideViewController. I would like to make it so that when there is a push from the FlipsideController to GaloreController, there will be an image appearing. The problem, however, would be that the image appearing depends on the configurations in the FlipsideController.

There are Segments for choosing the 'Puzzle', eg, if you chose the Apple Segment, there will be an Apple image appearing on the GaloreController, and so on.

In the SliderGaloreFlipsideViewController.h: (here I have the method so that when the ViewController is flipped, what to display on the GaloreController, but I don't know how to make implement the image method from this .m file as the image is in the Galorecontroller.m file.

- (IBAction)done:(id)sender
{
[self.delegate flipsideViewControllerDidFinish:self];

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You Ready?" message:@"Enjoy The Game!" delegate:nil cancelButtonTitle:@"Begin" otherButtonTitles:nil];

[alert show];
//UIImage *plate1 = [UIImage imageNamed:@"plates1.tif"];
//[imageView setImage:plate1];

In the SliderGaloreController.m:

- (void)viewDidLoad
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

self.tiles = [[NSMutableArray alloc] init];

NSString *Pic = [NSString stringWithFormat:@"image%d.jpg", [prefs integerForKey:@"PuzzlePicture"]]; //%d not %ld..
[self initPuzzle:Pic];

//UIImage *plate1 = [UIImage imageNamed:@"plates1.tif"];
//[imageView setImage:plate1];
//}

//UIImage *puzzleImage = [UIImage imageNamed:@"plates1.tif"];
//[imageView setImage:plate1];

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

Please explain on how I can have the image appear, DEPENDING on what segment is chosen from the SliderGaloreFlipsideViewController.

Well, one way to think about doing this is to have a UIImage property as part of the public interface of SliderGaloreController.

Then, when a segment is chosen, you can simple prepare for segue to the SliderGaloreController.m and set its image property to the appropriate configuration

So you have this property on SliderGaloreController.h for example:

@property (nonatomic, strong) UIImage *image;

Try this one :) If you just want to show a picture/image, i think this works.

UIImageView *plate1 = [UIImageView alloc] initWithImage:[UIImage imageNamed:@"plates1.tif"];
[self.view addSubview:plate1];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM