Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks as though <code>CustomImageView</code> is a subclass on <code>UIViewController</code>, not <code>UIImageView</code> or <code>UIView</code>. You <strong><em>can't</em></strong> add a <code>UIViewController</code> as a subview like that. change it to subclass <code>UIView</code> and it should work.</p> <p>To load a <code>UIView</code> from a .nib, you need to declare your <code>IBOutlet</code> properties as you would for a <code>UIViewController</code>. Define the correct custom class in IB and connect everything up, including the base view. Then override the following method inside your custom view class.</p> <pre><code>- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code. // [[NSBundle mainBundle] loadNibNamed:@"&lt;NIB NAME HERE&gt;" owner:self options:nil]; [self addSubview:self.view]; } return self; } </code></pre> <p>It seems you have cut and pasted methods from a <code>UIViewController</code> subclass into you <code>UIView</code> subclass. Start by deleting all the methods you've pasted in between <code>@synthesize</code> and <code>@end</code> . A <code>UIView</code> subclass requires different methods to to load from a .nib, so you need to override the method shown above instead and use the line of code</p> <p><code>[[NSBundle mainBundle] loadNibNamed:@"&lt;NIB NAME HERE&gt;" owner:self options:nil];</code></p> <p>to load the nib. </p> <p>Further to your comment about connecting the base view, here is what I mean:</p> <p>After creating your custom class and nib file, open the nib and highlight "Files Owner" on the left, then on the top right hand side, select the icon 3rd from the left, looks like an ID card or something. In the "Class" box, add the name of your custom class. </p> <p>In your customClass, add an <code>IBOutlet UIView</code> property called baseView, and add a UIView that covers the view in IB at the root level, connect these two. Then add everything else on top of that </p> <p>you code would now look something like this: </p> <p>CustomImageView.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface CustomImageView : UIView { IBOutlet UIView *baseView IBOutlet UIImageView *imageView; IBOutlet UILabel *caption; IBOutlet UIActivityIndicatorView *activityIndicator; } @property (nonatomic, retain) IBOutlet UIView *baseView; @property (nonatomic, retain) IBOutlet UIImageView *imageView; @property (nonatomic, retain) IBOutlet UILabel *caption; @property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator; @end </code></pre> <p>CustomImageView.m</p> <pre><code>#import "CustomImageView.h" @interface CustomImageView () @end @implementation CustomImageView @synthesize baseView, caption, imageView, activityIndicator; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code. // [[NSBundle mainBundle] loadNibNamed:@"&lt;NIB NAME HERE&gt;" owner:self options:nil]; [self addSubview:self.baseView]; } return self; } @end </code></pre> <p>Provided you connect it all up in IB it should work fine, just remember to add the baseView </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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