DACircularProgress icon indicating copy to clipboard operation
DACircularProgress copied to clipboard

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

Open wdragen opened this issue 11 years ago • 1 comments

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.

wdragen avatar Jan 16 '14 05:01 wdragen

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;
}

942v avatar Apr 08 '14 18:04 942v