new to UIView

Discussion in 'iOS Programming' started by pgeppl, Oct 12, 2009.

  1. pgeppl macrumors newbie

    Joined:
    Oct 12, 2009
    #1
    hi@all
    i am new to iphone programming and had a question
    i have 1 view controller and there is the automatic created view inside, ok.
    all interactions are working well.
    so i added a menu and when pressing a button a new view (UIView) which i already created in IB an did the property stuff in .h file too.
    now when i press the button on View1(which was automatic created and shown) i want to switch to the other view. but its not working hm
    what is the correct order to hide the first view and show the second view?

    this does not work:
    Code:
    [self.view addSubview:MySecondView]; // adding the new view to viewcontroller?
    [self.view removeFromSuperview]; // removing first,default view!?
    [self.view bringSubviewToFront:MySecondView]; // show the second, manual created, view
    
    BUT it does not work, whats wrong here
    maybe someone of you can help me out :)
    hopefully
    pille
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You have added the new view as a subview of the initial view: removing a view removed all it's subviews too.
     
  3. pgeppl thread starter macrumors newbie

    Joined:
    Oct 12, 2009
    #3
    http://picfront.de/d/gHtFRKXrOp7/Bildschirmfoto2009-10-12um10.33.13.png

    hi again
    so what i want to do is as following:
    View1 was autocreated with ViewController.xib
    so i added View2 manually

    all i want now is that when i press button 1 (action is called ok), i want to show View2 instead of View1 and also i want to add some IBActions and IBOutlets to View2!

    can you give me an example how this will work?

    thanks in advance
    pgeppl

    p.s.: ...ViewController.h
    Code:
    	UIView * MyFirstView;
    	UIView * MySecondView;	
    }
    
    @property (nonatomic,retain) IBOutlet UIView * MySecondView;
    @property (nonatomic,retain) IBOutlet UIView * MyFirstView;
    
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    If you are trying to change the whole screen then I would suggest you use a second view controller and push that onto the navigation stack. If you are trying to change a small part of the visible screen then just add and remove the views from the correct superview.

    Either way go back to the start: read all the documentation on Apple's website and actually understand what you are doing. It's very clear you have not done that and are trying to jump ahead without understanding the basics first.
     
  5. pgeppl thread starter macrumors newbie

    Joined:
    Oct 12, 2009
    #5
    you are right
    some of the basics i dont understand.
    i am new to object-C and the thing with Window, Views is not so really clear but when i read the doc, i tried, my questions are not answered for sure :(

    so maybe this is how it works
    i create a new project with a view controller.
    i add with IB a View1 and a View2 and a navigation bar.
    i have to code this in .h file that my project knows the 2 views.
    now i can switch between view1 and view2 and how can i resize the views on runtime?

    a small coding snippet would help very much ;)

    pgeppl
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    I am not about to write your code: copy/pasting for examples teaches you nothing. I have already told you how to proceed: read the documentation and ensure you understand it. Before writing any code all iPhone developers should have read and understood all of:

    iPhone Application Programming Guide
    iPhone Development Guide

    Had you done so you would know the answer.
     

Share This Page