Hi all,
I have a UIImage. This UIImage has to start from a UIView, and pass through a MainViewController to the FlipsideViewController. The UIImage is created with UIGraphicsGetImageFromCurrentImageContext(), which as far as I know can only be called from drawRect. Now the NSLog shows that the image has been generated from the UIView, but it appears
after the other log statements in the other classes. Obviously drawRect is taking its own sweet time, and the compiler is moving on. Here's the relevant code.
UIView.m:
Code:
(void) drawRect:(CGRect)rect
{
UIGraphicsBeginImageContext(self.bounds.size);
//drawing stuff
if (gettingImage == YES)
{
shapeImage = UIGraphicsGetImageFromCurrentImageContext();
gettingImage = NO;
}
UIGraphicsEndImageContext();
}
- (UIImage *) getUIImage
{
gettingImage = YES;
[self setNeedsDisplay];
return shapeImage;
}
MainViewController.m:
Code:
- (IBAction)showInfo:(id)sender {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
controller.delegate = self;
UIImage *shape = [viewer getUIImage]; //Viewer is an object of UIView
[controller getImageForFlipside:shape];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];
}
FlipsideViewController.m:
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *shapeImage = [[UIImageView alloc] initWithImage:shape]; //Shape is an instance variable UIImage
shapeImage.frame = CGRectMake(100.0, 126.0, shape.size.width, shape.size.height);
[self.view addSubview:shapeImage];
}
- (void) getImageForFlipside:(UIImage *)image
{
shape = image;
}
So everything compiles okay, but checking all the steps along the way gives me this:
Code:
2011-03-03 16:50:43.093 The Escherizer[95694:207] <UIImageView: 0x4b2af80; frame = (100 126; 0 0); userInteractionEnabled = NO; layer = <CALayer: 0x4b2b550>>
2011-03-03 16:50:43.095 The Escherizer[95694:207] shapeImage.image: (null) //This and above from FlipsideViewController
2011-03-03 16:50:43.100 The Escherizer[95694:207] shapeImage = <UIImage: 0x4b2c4d0> //from drawRect in UIView