title: Subclassing a custom UIView - How to init
body: <p>So let's say I have two views, <code>MyView</code> and <code>MySubview</code>, both of which subclass <code>UIView</code>.</p>
  
  <p>View.h:</p>
  
  <pre><code>@interface MyView : UIView &lt;ProgressCallback&gt;
  @property (retain, nonatomic) IBOutlet UIProgressBar *progress;
  
  - (id) initWithFrame: (CGRect) frame;
  - (void) progressUpdated: (NSNumber) newProgress;
  
  @end
  </code></pre>
  
  <p>View.m</p>
  
  <pre><code>@implementation MyView
  @synthesize progress = _progress;
  
  - (id)initWithFrame:(CGRect)frame;
  {
      self = [super initWithFrame:frame];
  
      if (self){
          NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"MyViewNibFile"
                                                                owner:nil
                                                              options:nil];
  
          if ([arrayOfViews count] &lt; 1){
              [self release];
              return nil;
          }
  
          View *newView = [[arrayOfViews objectAtIndex:0] retain];
          [newView setFrame:frame];
  
          [self release];
          self = newView;
  
          self.progress.progress = .25 // This will work and change it.
      }
  
      return self;
  }
  
  - (void) progressUpdated: (NSNumber) newProgress {
       self.progress.progress = newProgress.floatValue; // This also works!
  }
  </code></pre>
  
  <p>I found this method of creating a subclass of UIView by browsing Apple's docs and StackOverflow. It works, I can set my progress based on a callback, it appears, etc. My issue is when I want to subview this.</p>
  
  <p>MySubview.h</p>
  
  <pre><code>@interface MySubview : MyView
  @property (retain, nonatomic) IBOutlet UIImageView *image;
  @end
  </code></pre>
  
  <p>MySubview.m</p>
  
  <p>@implementation MySubview</p>
  
  <pre><code>- (id)initWithLabel: (UIImageView *) image andWithFrame:(CGRect)frame;
  {
      self = [super initWithFrame:frame];
  
      if (self){
          NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"MySubViewNibFile"
                                                                owner:nil
                                                              options:nil];
  
          if ([arrayOfViews count] &lt; 1){
              [self release];
              return nil;
          }
  
          MySubbiew *newView = [[arrayOfViews objectAtIndex:0] retain];
          [newView setFrame:frame];
  
          [self release];
          self = newView;
  
          self.progress.progress = .25 // This will work and change it.
          self.image = image; // Also works
      }
  
      return self;
  }
  </code></pre>
  
  <p>No matter how I initialize my subclass, I cannot get the progress bar to work in the subclass. I can set it during the init, and it is not nil, but it clearly does not correspond to the one in my view after the init. I think it has to do with the fact that I am releasing self, but I cannot see any other alternative if I want to return a class of type View. I use the same style of init, merely changing the class name to Subview. The callback actually is called and changes in code, but it does not update the display. Everything is hooked up correctly in the nibs, and they are identical except for size, and in this case, with an image.</p>
  
  <p>(I tried my best to make the example code as simple and as clear as possible. If I did not succeed, please let me know, I'll update it.)</p>
  
  <p>How do you properly subclass UIView? I read the docs, nothing proved enlightening, but please feel free to point me in the right direction. Specifically, what must I override to have everything pointing to the right items? That is, the ones on the display.</p>