Please clarify (removeFromSuperView)

Discussion in 'iOS Programming' started by arnieterm, Oct 17, 2008.

  1. arnieterm macrumors regular

    Aug 28, 2008
    A newbie question.
    For a UIView where I adds several objects [UIButton, UILabel, UIImage etc] using addSubView, if at a later time when I call
    removeFromSuperView for that UIView, does this will also release the objects that I have added to this UIView?
    Or do I need to run a while loop for subViews of UIView to individually release these objects.
    The nature of objects is a mixed one i.e. some objects are local [in the method where addSubView is called while others are declared at INterface level].
    I am asking this because I have to create a UIView with paging buttons [move next, move previous] that will pick up a group of rows from an array and show them in terms of UILabel and UIButtons. When the user click on next or previous buttons then the current page is clared and the next group is displayed.
    I have to use this option since I need to show multiple paging views on a single main view. Each paging getting its group from a different array.
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    When you addSubview, the added subview is retained. removeFromSuperView sends release. When a view controller is released its view hierarchy is also all released.

    This all follows the normal rules of memory management: If you retain it then you release it and never release something that you didn't retain.

    Regarding looping over the view hierarchy, you didn't retain those views so you don't release them. Just manage them with addSubview and removeFromSuperView.

Share This Page