Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Switching Views

appcodyappcody Posts: 17Registered Users
edited August 2011 in iPhone SDK Development
Hi,

I have been making buttons and making them take you to a different view once their tapped. I am currently using IBActions and defining them as View1 setHidden: Yes and View2 setHidden No, which just causes the other view to appear. This gets really tiring though when you need a different view to disappear (what I'm trying to say you can't just simply copy and paste). Is there a way of linking the buttons together into one code, like for example say that I have 50 different views, and all of them have one button for the main menu. I would have to make 50 IBActions, but I am looking for a way to say something like 'take user to "MainView" '. You would probably have to do it with an 'if', but I have no idea how to start this problem at all.

Thanks in advance,
Post edited by appcody on

Replies

  • MattWMattW Posts: 241Registered Users
    edited August 2011
    appcody;366181 said:
    Hi,

    I have been making buttons and making them take you to a different view once their tapped. I am currently using IBActions and defining them as View1 setHidden: Yes and View2 setHidden No, which just causes the other view to appear. This gets really tiring though when you need a different view to disappear (what I'm trying to say you can't just simply copy and paste). Is there a way of linking the buttons together into one code, like for example say that I have 50 different views, and all of them have one button for the main menu. I would have to make 50 IBActions, but I am looking for a way to say something like 'take user to "MainView" '. You would probably have to do it with an 'if', but I have no idea how to start this problem at all.

    Thanks in advance,
    I think you need to brush up on what View Controllers are for and how you switch between views. It sounds like you've got all views active at once and you hide the ones you don't want to see? That is completely the wrong approach.

    Read this: iPhone Programming Tutorial ? Transitioning Between Views | iPhone Programming Tutorials
    [SIGPIC][/SIGPIC]

    Highlight PDF text like no other app: iHighlight (now available for iPad and iPhone!)

    -----

    Create iPhone lists with no typing: <a
  • appcodyappcody Posts: 17Registered Users
    edited August 2011
    MattW;366185 said:
    I think you need to brush up on what View Controllers are for and how you switch between views. It sounds like you've got all views active at once and you hide the ones you don't want to see? That is completely the wrong approach.

    Read this: iPhone Programming Tutorial ? Transitioning Between Views | iPhone Programming Tutorials

    Hi,

    Thanks for your reply. I know how to use the navigation controllers and view controllers though. So should I just make a view, link it to a view controller, but instead of the 'didselectrowatindexpath' should I say something like 'didselectbutton'? I would have to switch everything to something else. And its more of a game, so I can't really use the navigation controller with table cells.
  • appcodyappcody Posts: 17Registered Users
    edited August 2011
    Hi,

    I am bumping my thread so it gets noticed again, because right now its on page 3, and is not likely to get any more attention.

    I have tried to solve my problem (the one stated at the very top), but I couldn't figure it out yet. I tried implementing the ModalView, but I don't want it to be a ModalView, because I need it to be another 'main' screen.
  • appcodyappcody Posts: 17Registered Users
    edited August 2011
    Hi,

    does anybody know how to solve my problem? I'm still stuck on it.

    Thanks,
  • JustinmichaelJustinmichael Posts: 210
    edited August 2011
    appcody;367319 said:
    Hi,

    does anybody know how to solve my problem? I'm still stuck on it.

    Thanks,
    Yeah, say you have 2 screens (saying screen not to confuse with UIView). Screen 1 = menu, Screen 2 = game.

    Screen 1 and 2 (GameScreen) would extend UIViewController. When someone hits your button you call your IBAction and present the view modally. You can change the animation for entry but I'll leave you to look at the docs for that (or you can set to NO to make it instantly show):


    - (IBAction)didHitPlay {
    GameScreen* gameScreen = [[GameScreen alloc] init];
    [self presentModelViewController:gameScreen animated:NO];
    [gameScreen release];
    }

  • penpaperpenpaper Posts: 9New Users
    edited August 2011
    Justinmichael;367321 said:
    Yeah, say you have 2 screens (saying screen not to confuse with UIView). Screen 1 = menu, Screen 2 = game.

    Screen 1 and 2 (GameScreen) would extend UIViewController. When someone hits your button you call your IBAction and present the view modally. You can change the animation for entry but I'll leave you to look at the docs for that (or you can set to NO to make it instantly show):


    - (IBAction)didHitPlay {
    GameScreen* gameScreen = [[GameScreen alloc] init];
    [self presentModelViewController:gameScreen animated:NO];
    [gameScreen release];
    }

    Thanks for your reply. I tried implementing that, and I got everything to work, except that when I build and run I get an error that I need to declare the 'GameScreen'. I made an xib with the name of GameScreen though. And the window is linked to the GameScreenViewController. Any ideas?

    Thanks
  • JustinmichaelJustinmichael Posts: 210
    edited August 2011
    penpaper;367334 said:
    Thanks for your reply. I tried implementing that, and I got everything to work, except that when I build and run I get an error that I need to declare the 'GameScreen'. I made an xib with the name of GameScreen though. And the window is linked to the GameScreenViewController. Any ideas?

    Thanks
    Yeah, I made GameScreen up. I should have been clearer, you need to replace this with the classname of your second UIViewController (which you can add a nib for when you create if you like).
Sign In or Register to comment.