Constructor for UIView

Posted by Tres Thu, 30 Apr 2009 23:24:00 GMT

So you’re trying to initialize your UIView and have found various conflicting sources of information on Google & a lack of clear documentation in the Apple API documentation?

Contrary to the boilerplate code included by XCode, initializing a UIView isn’t a matter of calling initWithFrame:. Instead, try initWithCoder: as shown here:

- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder:decoder]) {
        [self initializeBlablah];
        [self setBrainzaiWithStuff: stuff];

    }
    return self;
}

Good to go!

Posted in , ,  | Tags

Comments are disabled