i want to di开发者_如何学Pythonsplay an UIImage within a UIImageView but it doesn't work and i don't know why. could you please help me.
i am using the following coding:
-(void) showCorrectedImage {
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
CorrectedImageController *imageController = [[CorrectedImageController alloc] initWithNibName:@"CorrectedImageView" bundle:nil];
UIImageView *imgView = [[UIImageView alloc] initWithImage:originalImage];
imageController.imageView = imgView;
[imgView release];
[delegate.navController pushViewController:imageController animated:YES];
}
There is a xib file called "CorrectedImageView.xib" and within the xib i have placed an UIImageView. I have connected the UIImageView outlet with the image view and the view outlet with the view. original Image is defined as UIImage and initialized with a file.
br., martin
In these lines
UIImageView *imgView = [[UIImageView alloc] initWithImage:originalImage];
imageController.imageView = imgView;
[imgView release];
you're creating a new UIImageView instance, when you already have one in the XIB file. If your connections in IB are good, this should be all you need to do:
imageController.imageView.image = originalImage;
Also, please don't forget to release imageController after you push it like this:
[imageController release];
P.S. As to why your code doesn't work, the newly created UIImageView instance, while it replaces the previous one in the view controller, it's not added as a subview of the view controller's view. So after your code executes, you have:
- An UIImageView instance retained as a subview of the main view.
- Another UIImageView instance initialized with your image and retained in the view controller, but not a subview of the main view, and therefore not displayed.
sorry, but i don't get it running. maybe my nib file is wrong. it looks as follows:
-File's Owner (CorrectedImageController)
-First Responder (UIResponder)
-View (UIView)
--ImageView (UIImageView9
I've connected the File's Owner view property to the View Element and the File's Owner imageView property to the ImageView Element.
Did i miss something ?
BR, Martin
精彩评论