initwithframe

Objective C - Custom view and implementing init method?

北城余情 提交于 2019-11-27 10:45:23
I have a custom view that I want to be able to initialize both in-code and in nib . What's the correct way to write both initWithFrame and initWithCoder methods? They both share a block of code that is used for some initialization. The right thing to do in that case is to create another method containing the code that's common to both -initWithFrame: and -initWithCoder: , and then call that method from both -initWithFrame: and -initWithCoder: : - (void)commonInit { // do any initialization that's common to both -initWithFrame: // and -initWithCoder: in this method } - (id)initWithFrame:(CGRect

Objective C - Custom view and implementing init method?

谁都会走 提交于 2019-11-26 17:58:19
问题 I have a custom view that I want to be able to initialize both in-code and in nib . What's the correct way to write both initWithFrame and initWithCoder methods? They both share a block of code that is used for some initialization. 回答1: The right thing to do in that case is to create another method containing the code that's common to both -initWithFrame: and -initWithCoder: , and then call that method from both -initWithFrame: and -initWithCoder: : - (void)commonInit { // do any