iphone sdk how to switch an image and save it with a button press
I'm writing an application where I want an image to be displayed on the first page, but only on a small portion of the front page. What I've been trying to do is set up a button on a subview that will sw开发者_StackOverflow中文版itch the image on the first view. This has had me stumped for hours. Can anyone help?
Assuming that your view controller has a member variable named 'myImageView' that's hooked up to the actual UIImageView, then you can change a UIImageView's image, as follows (caveat: I haven't compiled this code so it may have minor errors):
// create some images
UIImage *imgPig = [[UIImage imageNamed:@"pig.png"] retain];
UIImage *imgCow = [[UIImage imageNamed:@"cow.png"] retain];
...
// sometime later, change the imageview to show a pig
[[self myImageView] image] = imgPig;
...
// sometime later, change the pig to a cow
[[self myImageView] image] = imgCow;
// finally release images
[imgPig release];
[imgCow release];
Or is the problem that you have about how to access the actual UIImageView? Or is it that you don't know how to detect the button press so that you can actually do something in response to the button being pressed?
Yes, that's right. I have three .h and .m files: appdelegate, the viewcontroller, and then a subview. What I'm trying to do is let the user change the image to a different image on the first page by using a button located on the subview. On the first view there's a label and a UIImageView (This imageview is the one i want to change). On the second view there's a UIButton. When this button is pressed, it should change the UIImageView on the first page. The problem I've been having is letting the first page know that the button has been pressed, and changing the picture accordingly. Hope thats enough info for you to help. thanks!!
[edit to guy below me: sorry, I switched comptuers and couldnt edit the original post]
精彩评论