Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that your solution #3 adds unnecessary complexity by introducing a UIViewController instance just as a container for your ProgressView so that you can setup nib bindings. While I do think that it is nice to be able to work with an IBOutlet bound property rather than iterating through the nib contents you can do so without introducing a UIViewController whose behavior you neither need nor want. This should avoid your confusion around how and when to release the view controller and what, if any, side effects it might have on the responder chain or other behaviors of the loaded view.</p> <p>Instead please reconsider using NSBundle and taking advantage of the power of that <code>owner</code> argument.</p> <pre><code>@interface ProgressViewContainer : NSObject { } @property (nonatomic, retain) IBOutlet ProgressView *progressView; @end @implementation ProgressViewContainer @synthesize progressView = progressView; - (void) dealloc { [progressView release]; [super dealloc]; } @end @interface ProgressView : UIView { } + (ProgressView *) newProgressView; @end @implementation ProgressView + (ProgressView *) newProgressView { ProgressViewContainer *container = [[ProgressViewContainer alloc] init]; [[NSBundle mainBundle] loadNibNamed:@"ProgressView" owner:container options:nil]; ProgressView *progressView = [container.progressView retain]; [container release]; return progressView; } @end </code></pre> <p>Create a nib named "ProgressView" containing a ProgressView and set it's File's Owner class to ProgressViewContainer. Now you can create ProgressViews loaded from your nib.</p> <pre><code>ProgressView *progressView = [ProgressView newProgressView]; [scrollView addSubview:progressView]; [progressView release]; </code></pre> <p>If you have multiple configurations of your progress view then maybe you'll want to implement a <code>-initWithNibNamed:</code> method on ProgressView instead of <code>+newProgressView</code> so you can specify which nib to use to create each ProgressView instance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload