UIView: At what point can I start calling methods on my properties?

Discussion in 'iOS Programming' started by moonman239, Aug 18, 2015.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I have a UIView named Alice. Alice has an image view named Bob. Bob is connected to Alice via an IBOutlet. Sometime immediately after Bob is initialized, Alice will need to set his "hidden" property. I can override Alice's addSubview method and check to see if Bob is the view to be added, and if he is, set view's hidden property to true. However, is there another way to do what I want without manually registering Alice as an observer?
     
  2. grandM macrumors 6502a

    grandM

    Joined:
    Oct 14, 2013
    #2
    Doesn't your question depend on the if clause
    That clause determines if Bob ought to be hidden or not
     
  3. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #3
    No. The code will do something like this:

    If view is Bob, then hide it.
     
  4. bjet767 macrumors 6502a

    Joined:
    Oct 2, 2010
    #4
    I'm not sure what you want to do, but I have an app in the Store which does something similar.

    What I needed to do was have a simple single view app with two views. Ok what I did was stack two views on top of each other. Both views get initialized through one view controller and the top view is hidden under two basic conditions. The first is the initial opening of the app when user data is required to be added. The second is when the user wants to change his or her data, which is done by selecting a menu bar item.

    One thing I noticed is you put your "outlet" for bob in the UIView class. Normally I would think this is not the suggested way of doing things. Wouldn't it make more sense to use you view controller for all the actions and outlet work? Most views have multiple types of views within them.
     

Share This Page