开发者

How should I subclass NSWindow initialization in Objective-C

i want to create a subclass of NSWindow. this subclass needs to initialize some member variables before they are used. what is the best way to capture initialization in objective c? what i find is that init rarely gets called in a way that allows me to do t开发者_如何学运维his. NSWindow has a couple of initialization vectors that i would need to override. do i need to override each of them?


Each class should have one so-called designated initializer. This is the init method that all other init methods call. That's the one to override. The documentation usually tells you which one the designated initializer is. In the case of NSWindow, it is:

initWithContentRect:styleMask:backing:defer:

This method is the designated initializer for the NSWindow class.

In addition to the designated initializer, you should also override -initWithCoder: if the class you subclass implements the NSCoding protocol. -initWithCoder: is the initializer that is used when an instance is instantiated from an archive (such as a NIB file).

See The Designated Initializer in Apple's "The Objective-C Programming Language".


Have you tried overriding the designated initialiser

- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)deferCreation screen:(NSScreen *)screen

Documentation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜