То, что вы пытаетесь сделать, технически нормально, но на каком-то этапе вам нужно вызвать [super init]
. Если метод init
вашего класса выполняет обычную инициализацию, которую используют другие методы initWith...
, поместите туда [super init]
. Кроме того, всегда проверяйте, что класс был init
', прежде чем пытаться поиграться с переменными экземпляра.
- (id) initWithKeyPadType: (int)value
{
self = [self init]; // invoke common initialisation
if( self != nil )
{
[self setKeyPadType:value];
}
return self;
}
- (id) init
{
self = [super init]; // invoke NSObject initialisation (or whoever superclass is)
if (!self) return nil;
NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init]
autorelease];
decimalSymbol = [formatter decimalSeparator];
...