Problem with view only showing in background...

Discussion in 'iOS Programming' started by SunnyLi, Oct 15, 2010.

  1. Guest

    Joined:
    Oct 7, 2010
    #1
    Hi Guys,

    I have a problem with one of my views, it has some squares drawn on it and you can only see it if you are switching a view say to go to settings so its right at the back.

    i can change it in the appdelegate from this where it shows in the background:

    Code:
    	
    	MainView *view = [[MainView alloc] initWithFrame:[window frame]];
    	[window addSubview:view];
    	[view release];
    	
        mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
    	[window addSubview:[mainViewController view]];
    	
    	
    To this but it then covers up the controls on the bottom of the screen:

    Code:
      mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
    	[window addSubview:[mainViewController view]];
    	
    	MainView *view = [[MainView alloc] initWithFrame:[window frame]];
    	[window addSubview:view];
    	[view release];
    	
        [window makeKeyAndVisible];
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    What is the purpose of mainViewController and what is it's relationship to view?
     
  3. thread starter Guest

    Joined:
    Oct 7, 2010
    #3
    I have the mainviewcontroller which has all my buttons etc on and then this mainview which is used for drawing all the squares on.
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Again, I ask: what is the relationship between the two views? Is view some kind of background view to mainViewController's view? Clearly, if each view takes the entire window frame, they both cannot display at the same time (assuming they are both opaque).
     
  5. thread starter Guest

    Joined:
    Oct 7, 2010
    #5
    Yeh thats what i wanted to do, have the squares drawn on the background of the mainviewcontroller. But in the drawing tutorial it showed me to do it this way with the drawing on a separate view.
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Which tutorial? Do you have a link?
     
  7. thread starter Guest

    Joined:
    Oct 7, 2010
    #7
  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    If all you're doing is drawing circles, triangles and rectangles, it's fine. But it just overlaps the main (default) view with the custom one. The problem is you're now trying to add some UI elements for interactivity and for some reason you feel two separate views are necessary to implement it. It's possible but you need to rethink the relationship as well as the layering between the two views. But it's also possible to implement the concept using a single view.
     
  9. thread starter Guest

    Joined:
    Oct 7, 2010
    #9
    Could I just move all the drawing code from mainview to the mainviewcontoller?
     
  10. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #10
    Controllers don't draw. Views do.
     

Share This Page