title: Change a subview at run time in iOS
body: <p>In the initialization of my view controller I declare a view and I set it as a subview of the main view:</p>
  
  <pre><code>self.customView = [[UIView alloc] initWithFrame:self.view.frame];
  self.customView.backgroundColor = [UIColor redColor];
  
  [self.view addSubview:self.customView];
  </code></pre>
  
  <p>Later on, in a method I need to substitute <code>self.customView</code> for another view. (Note: changing the background color is just a simplified example. The views are more complex than that).</p>
  
  <pre><code>UIView *anotherView = [[UIView alloc] initWithFrame:self.view.frame];
  anotherView.backgroundColor = [UIColor blackColor];
  self.customView = anotherView;
  </code></pre>
  
  <p>But this has no effect. However if I instead make something like:</p>
  
  <pre><code>[self.view addSubview:anotherView];
  </code></pre>
  
  <p>It works fine. I want however to get rid of the previous view without localizing and removing the view explicitly. Isn't it possible to substitute a subview at runtime or I am missing something?</p>
  
  <p>I work with ARC. Thanks!</p>