Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios UIView no init calls

Tags:

ios

My current storyboard layout

UIViewController
  |
  +- UIView (MyView)

in MyView I have the following functions built out

  • init
  • initWithFrame
  • initWithCoder
  • awakeFromNib
  • awakeAfterUsingCoder

Out of those five, only two actually run

  • awakeFromNib
  • awakeAfterUsingCoder

I've scoured for a while and I can't figure out why the init functions aren't working.

like image 829
Jacksonkr Avatar asked Mar 01 '26 20:03

Jacksonkr


1 Answers

Per my comment up top:

@MichaelDautermann it was something simple. This is two days in a row now. I had - (id)initWithCoder:(NSCoder *)aDecoder:(CGRect)frame. Why is that it takes me so long to see these n00b mistakes? I don't know. In my defense, Xcode didn't give me any build errors.

Incorrect code I had:

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

Correct code:

- (id)initWithCoder:(NSCoder *)aDecoder {
    if(self = [super initWithCoder:aDecoder]) {
        //
    }
    return self;
}
like image 106
Jacksonkr Avatar answered Mar 03 '26 09:03

Jacksonkr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!