Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not be showed successfully when make it as a component of my self-defined view when load from xib #20

Open
wdragen opened this issue Jan 16, 2014 · 1 comment

Comments

@wdragen
Copy link
Contributor

wdragen commented Jan 16, 2014

I have a self-defined view. And it has a DACircularProgressView as subview.

@interface TestView : UIView
{
    DACircularProgressView *_progressView;
}
@property(nonatomic, strong)DACircularProgressView *progressView;

And I want this TestView loaded from xib files. So my implementation file as below:

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

- (void)awakeFromNib
{
    [self _myInitialize];
}

- (void)_myInitialize
{
    _progressView = [[DACircularProgressView alloc] initWithFrame:self.bounds];
    _progressView.trackTintColor = [UIColor grayColor];
   _progressView.progressTintColor = [UIColor greenColor];

   [self addSubview:_progressView];
}

When add my TestView to my view controller's xib file, I can't see the right progress view. While when I alloc my TestView in viewDidLoad method, and add it to my self.view, I can see the right progress view. I want know why? Is there any mistake I have made? Thanks advance.

@942v
Copy link

942v commented Apr 8, 2014

This is because the XIB calls initWithCoder and not initWithFrame. Just add this below initWithFrame

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Custom Setup
        [self _myInitialize];
    }
    return self;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants