Question about multiviews

Discussion in 'iOS Programming' started by JLatte, May 19, 2009.

  1. JLatte macrumors 6502

    Joined:
    Dec 2, 2005
    Location:
    San Diego
    #1
    I've been bashing my head over views the past couple of days. I don't want set up navigation controller or tab bar controller, I simply want to create a very basic view based application.

    Screen 1 loads, says "Intro screen" with a button that allows you to go to screen 2 (Create Account Screen). Right now with this code, it works. Since I'm using initWithNibName I understand that I would want to override the viewdidload function. I didn't do this, however it still displays, but I have a feeling this isn't what I want in the long run for a larger scale program with many screens.

    My question is this: If I'm not mistaken, when I used self.view addSubview, all this does is after the view is created is push the new view to the front of the other views. If I eventually have a lot of screens, I don't want to have 10+ views loaded in the background as this would kill the memory.

    When I was reading around, I keep seeing the documentation mentioning removeFromSuperview. I threw in [self.view removeFromSuperview] right before [self.view addSubview:createAccount....] however obviously that doesn't work, and it removes the view entirely and then has nothing to display the new view on.

    What's the proper way to release the current screen I'm viewing in exchange for pushing the new view onto the stack? How do I call the current view only for the screen I'm currently viewing? Is the only way to do this by creating one master root view controller that has ALL of the ibactions for each of the buttons and then controlling everything through this?

    Thanks in advance for the help.

    Code:
    -(IBAction)goToCreateAccountView:(id)sender
    {
    	if (self.createAccountViewController == nil)
    		{
    			CreateAccountViewController *createAccountController = [[CreateAccountViewController alloc] initWithNibName:@"CreateAccountView" bundle:nil];
    			self.createAccountViewController = createAccountController;
    			[createAccountController release];
    			NSLog(@"View loaded.");
    		}
    	[self.view addSubview:createAccountViewController.view];
    }
     
  2. JLatte thread starter macrumors 6502

    Joined:
    Dec 2, 2005
    Location:
    San Diego
    #2
    Man, is my question that obscure? :eek:

    I still haven't solved my problem, and I even tested it by performing a rotate animation without changing screens on a new view after I've loaded it on top of the previous views... the views underneath are still there and are clearly visible when it does the rotation.

    Anyone?
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    You feel entitled to an answer, do you?
     
  4. JLatte thread starter macrumors 6502

    Joined:
    Dec 2, 2005
    Location:
    San Diego
    #4
    I'm not quite sure I'm following you here.

    *edit*
    Actually, I'm not even really sure why you'd write this and not help out with a question that may be simple for you. I've seen you help many people on these boards. I've helped many people as well, however not near to the number you have. Do you have some issue with the way I gave a little bump 5 hours later? I didn't just bump it you know, I also wrote that I tested out some more with my problem. In my OP, I didn't just ask for help without providing any code or anything, what did I do wrong? Gave code sample, very clearly (in my opinion) wrote out my problem and question, so I have to ask what it is you don't like about my post?
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Sorry if that came out harsher than you liked. Just seemed to me that the opening and closing of your second post were unnecessary. You cannot always expect anyone to know the answer to a query, have time to respond, or various other reasons for not replying. I know I've had a post or two that never got any response but that's life.

    I have no problem with your initial post and will look at it in more detail in the morning (for me) and see if I can help.
     
  6. JLatte thread starter macrumors 6502

    Joined:
    Dec 2, 2005
    Location:
    San Diego
    #6
    Sorry I figured the emoticon would make it come off less serious than you took it. I don't expect anyone to know the answer right away, I was just doing a shameless bump while relaying that I'm actually trying to fix the problem myself on the side instead of just asking and not trying to do anything about it myself. Anyways, if you can help, thanks if not thanks anyways for looking.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Yeah, sorry. Guess I just took issue with the shameless bump part of it (bumping is against forum rules by the way) and not the update to what you had tried. Giving us updates are never a bad thing.

    Anyways, back to the original topic. (Sorry for derailing things a bit).

    You may want to look at a basic Utility Application and see how it handles multiple views. Also, Chapter 6 of "Beginning iPhone Development" is all about Multiview Applications and the code for it is available online.

    Basically, you want to have a viewController that handles your subviews. That way you are not adding the second subview to the first but instead to a super view. Capiche?
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    Few comments:

    First, don't do it this way. Use a navbar. Navbars are standard. Navbars are easy. When you ask a question in this forum about them you will get an answer. If you really don't want the appearance of a navbar consider that you can have a hidden navbar that still works to push and pop views.

    Second, if you do it your own way then you're on your own. I guess that a lot of games are done this way with adding and removing views manually. I see a lot of questions on this topic and not so many answers. The utility app that flips from frontside to backside and back does this sort of thing.

    The smart thing would be to write your own class that duplicates the things that the nav controller does.
     

Share This Page