Class with a custom initializer


#1

I have been trying to expand the concepts that were covered in this chapter and I’m having issues.

I have a group of NSPopUpButton and I’m trying to submit a custom initializer instead of the standard. Sometimes I get the submission of the custom and the standard. With other changes, only the custom.

The top submission is the way it should be. The second is the standard init as a test. The populate instance button is there only to get the first submission to populate properly. I would prefer it not to be there.

submitInteraction method in TrackerDocument.m

- (IBAction)submitInteraction:(id)sender { Interaction *current = [[Interaction alloc] initWithIntNumber:i time:[timeStamp stringValue] type:[interactionType titleOfSelectedItem] tier1:[tier1Cat titleOfSelectedItem] tier2:[tier2Cat titleOfSelectedItem] tier3:[tier3Cat titleOfSelectedItem] intDes:[description stringValue]]; [interactionArray addObject:current]; [self resetUI]; }

Interaction.m

-(id) init
{
    if (self){
        intNumber = 1;
        timeStamp = @"RIGHT NOW!!!";
        interactionType = @"KITTIES";
        tier1Cat = @"PUPPIES!";
        tier2Cat = @"STUFF";
        tier3Cat = @"Things!";
        intDescription = @"default test values to test posting to array and tableView";
    }
    
    return self;
}

- (id) initWithIntNumber:(int)i time:(NSString *)tempStamp type:(NSString *)intType tier1:(NSString *)t1c tier2:(NSString *)t2c tier3:(NSString *)t3c intDes:(NSString *)des{
    self = [super init];
    if (self){
        intNumber = i;
        timeStamp = tempStamp;
        interactionType = intType;
        tier1Cat = t1c;
        tier2Cat = t2c;
        tier3Cat = t3c;
        intDescription = des;
    }
    return self;
}

Can someone give me insight? I have been looking in other forums and asking the same question with no results.


#2

Hard to tell, but something unusual has caught my eye.

Your init method is unorthodox. Neither it is calling its super init nor a designated initialiser.


#3

The custom init does call the super init if you scroll down a little. The custom init is the designated initializer. The standard init is just there for testing purposes.


#4

Fixed it.

Declared an IBOutlet for the controller and made the connection from File’s Owner to the Controller in the XIB.

then

[code][Interaction *current = [[Interaction alloc] initWithManyArguementsHere:blah]

[intController addObject:current]
[/code]