Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As mentioned earlier <code>initWithNibName</code> belongs to controllers.<br> As I think, you're going the wrong way.</p> <p>you have a ViewController and want to add a customView, to load dynamically a image from URLData.</p> <p><em>You have 2 Options:</em><br> <strong>Option 1:</strong> Do everything in IB:<br> In Interfacebuilder edit/(or add a new one) the ViewController's XIB File and add the views that you like. The file's owner is a UIViewController Class/Subclass. Do everything like you did before, except doing it in the view controller. In your App delegate initWithNibName your ViewController like so </p> <pre><code> self.viewController = [[testViewController alloc] initWithNibName:@"testViewController" bundle:nil]; </code></pre> <p>If you want to, initialize your own view controller, which you like to push and push it in the stack.</p> <p>What you're doing wrong: You are initializing a customImageView with a Frame, but the nib doesn't get loaded automatically. The Properties are there, but the nib isn't.</p> <p>If you really want a stable thing choose<br> <strong>Option 2: Do everything programatically</strong> (It is easier, more understanding and lightweight):<br> From your implementation we do the following: </p> <p><strong>NewsViewController.m</strong></p> <p>Do like you did before!!!</p> <p><strong>CustomImageView.h:</strong> </p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface CustomImageView : UIView { UIImageView *imageView; UILabel *caption; UIActivityIndicatorView *activityIndicator; } @property (nonatomic, retain) UIImageView *imageView; @property (nonatomic, retain) UILabel *caption; @property (nonatomic, retain) UIActivityIndicatorView *activityIndicator; @end </code></pre> <p><strong>CustomImageView.m:</strong> </p> <pre><code>- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code caption = [[UILabel alloc] initWithFrame:CGRectMake(0, 250, 320, 50)]; [caption setBackgroundColor:[UIColor greenColor]]; imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 250)]; [imageView setBackgroundColor:[UIColor blueColor]]; activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; self.activityIndicator.frame = CGRectMake(320/2-25, 460/2-25, 50, 50); [self.activityIndicator startAnimating]; [self addSubview:self.caption]; [self addSubview:self.imageView]; [self addSubview:self.activityIndicator]; } return self; } </code></pre> <p>Then do everything you did before. That would do a better job</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