views:

321

answers:

1

Hi guys,

I am almost at the end of coding my kids educational application, woohoo!.

But... Im stuck on something.

When app loads i have my main view. It has 4 buttons for flipviews(each with ten views of content) and 4 buttons for character selection(an image that will follow you through every screen of content).

Problem is im unsure on how to link UIButton selection to UIImage display in multiple views. I want the user to choose a character button and then continue to the flipviews and in the views the image displayed should be the one that they have selected on the main view. So everytime they return to the main view they can change the character that will follow them around the app.

Any thoughts, help or code would be much appreciated!

Thank You

Alex

A: 

Make a new object, a subclass of UIImageView, which has a -setImage method. Once you set the image, then where ever you embed that object, it will display the same image. You could even have that subclass view have a score displayed next to it, or a name or other stats, so as you go from one screen to another, you have all that info follow you around with the image. No need to create labels in all the screens for global info like that.

In summary:

  • make a new subclass of UIView or UIImageView in Xcode using the New File... menu. You would do new UIView if you will have other items than just an image.
  • add methods that allow you to set the image, update text stats etc.
  • BONUS: you can make the class handle taps, so if a user taps the image, you could do something like provide help or run a cute little animation
  • embed that object in any screens you wish. Keep in mind that you can have that view be sized differently in each screen using transforms. Cool, no?
  • that's pretty much it!

Good luck!

mahboudz
Oh, thanks for the quick reply! That is definately what im trying to do, but i think im going to need to see some code, will keep searching the docs but i am at work at the moment :)
Alex
This is pretty easy. You are creating a new class, subclass of UIView. Look for Apple's samples with files that end with View, instead of viewController, etc. Once you find one where in the .h file it says something like @interface fooView : UIView {, then read that. TheElements sample has a bunch of views, but has too much other baggage. Once you have that class defined, then anywhere else in your code, like in different screens, you can throw in a new instance of your class, and you can even resize or animate it (float it around the screen)...
mahboudz