Adding a custom subview (created in a xib) to a view controller's view - What am I doing wrong

Posted by Fran on Stack Overflow See other posts from Stack Overflow or by Fran
Published on 2011-03-18T16:02:31Z Indexed on 2011/03/18 16:10 UTC
Read the original article Hit count: 340

Filed under:
|
|
|

I've created a view in a xib (with an activity indicator, a progress view and a label). Then I've created .h/.m files:

  #import <UIKit/UIKit.h>

  @interface MyCustomView : UIView {
         IBOutlet UIActivityIndicatorView *actIndicator;
         IBOutlet UIProgressView *progressBar;
         IBOutlet UILabel *statusMsg;
  }

  @end

  #import "MyCustomView.h"

  @implementation MyCustomView    

 - (id)initWithFrame:(CGRect)frame {
          if ((self = [super initWithFrame:frame])) {
          // Initialization code
   }
   return self;
   }

 - (void)dealloc {
     [super dealloc];
  }

  @end

In IB, I set the file's owner and view identity to MyCustomView and connect the IBOutlet to the File's owner

In MyViewController.m, I've:

 - (void)viewDidLoad {

       [super viewDidLoad];   

       UIView *subView = [[MyCustomView alloc] initWithFrame:myTableView.frame];
       [subView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]];

       [myTableView addSubview:subView];
       [subView release];
}

When I run the app, the view is added, but I can't see the label, the progress bar and the activity indicator.

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about ios