1

I'm trying to build an educational app that will have approximately 3-5 completely different pages/screens. Each screen contains one puzzle and each puzzle is independent of all the other puzzles (screens). Once the puzzle on the current screen is solved I'd like to transition to a new (randomly selected) screen. I would allow the same puzzle to be shown multiple times, however, if it had been displayed before it would need to be reset.

I've tried doing this using segues but that seems to require a UINavigationController which is not the experience I want to present (since it requires a predefined hierarchy of screens).

I assume the best way to do this is to have each screen as completely separate UIViewControllers, correct? I'm just not sure how to orchestrate the navigation/rendering between them.

I'd appreciate whatever best practices you know of. Thanks!

JJensL
  • 149
  • 1
  • 13

4 Answers4

2

Well here is a possible option:

First of all if you want a menu outside of these puzzles have that as your root view controller in a UINavigationController.

Then create a launcher controller and add it to the navigation controller when appropriate. This will be a regular UIViewController except in this controller in the viewWillAppear method have it pick a random number 0-5 and run it through a switch and depending on the number push one of your 5 view controllers. Then when the puzzle is completed call popViewController on the navigation controller. Now when it pops back, viewWillAppear will be called again and randomly push another. Then if you want to go back to the main menu at any time just call popToRootViewControllerAnimated. This should do what you need. And to make it so it doesn't animate twice either only have the push animate or only the pop.

Alessandro Vendruscolo
  • 14,493
  • 4
  • 32
  • 41
user1084563
  • 2,149
  • 17
  • 28
  • Interesting, this seems to be the most intuitive solution to me thus far. I'll give this a try and let you know my results. – JJensL Dec 09 '11 at 13:42
  • I've tried this solution and I'm really close but I'm missing something. I don't want to transition to the next view until the "success" sound has finished playing. So I placed the popViewController call in my AudioServicesSystemSoundCompletionProc. However, after I complete the second puzzle I get an EXC_BAD_ACCESS error. I see that this is the line causing the problem:`[((__bridge ColorsAppViewController *) clientData).navigationController popViewControllerAnimated:false];` I assume EXC_BAD_ACCESS means my viewcontroller has been dereferenced I just don't understand why that's the case. – JJensL Dec 13 '11 at 05:32
0

Rather than having different view controllers you can have a single controller. You can reload the view of the puzzle after completing the first. The logic you have applied for the first puzzle will be some what similar to the the others. So now only you need to handle different states of the puzzle. For example: I have first view with puzzle 3x3 matrix, the next will be 4x4 matrix and the next will be 5x5 matrix. So this states needs to be handled through code in view controller.

iamsult
  • 1,581
  • 1
  • 15
  • 21
  • Couple of (newbie) questions about this. 1) if I have multiple views defined in one controller, can I still view each one in the Storyboard view of XCode? 2) All the example code I've seen shows a tight coupling between UI elements on a view and the controller, for your solution it sounds like I'd need to move that logic down to a custom UIView class I'd need to create, correct? 3) How do I programatically force a View to be re-rendered (which also resets all the UI elements)? – JJensL Dec 09 '11 at 13:54
0

I know that using cocos2d is a great way to build games and it allows different "scenes" where things are independent of each other or can communicate if you choose. Also with cocos2d there is a "director" that handles all of the scenes and can push scenes for you. If you are curious check out: www.cocos2d-iphone.org

I hope this helps :)

tams
  • 830
  • 5
  • 9
0

Well, I was build the app tested yesterday to play different music instrument. I use UIView to handle view for 3 of my instrument. The logic is simple. I put the navigation on UIButton and add a subview for each instrument. When the user touch the button, the selected view will be add to the front, and the last view will be release or temporary on the background.

Hope it will help you.

Shanti K
  • 2,873
  • 1
  • 16
  • 31
caknia
  • 1,221
  • 2
  • 13
  • 24