nstreecontroller does not call any init methods

Discussion in 'Mac Programming' started by MrFusion, Aug 13, 2009.

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    Hi everyone

    My subclass of NSTreeController has a delegate, which can be set in IB. If no delegate is set, my subclass should act as the delegate. So I have to do this before awakeFromNib is called, which means in the init method of my subclass.

    However, init and initWithContent are never called. I have no idea why. Some init method should be the first method that is called.

    The content is provided by coredata.

    Code:
    @synthesize delegate;
    
    -(void) setDelegate:(id) value {
    	if (!value)
    		delegate = self;
    	delegate = value;
    }
    
    -(id) initWithContent:(id)content { printf("initwithcontent");
    	self = [super initWithContent:content];
    	if (self != nil) {
    		delegate = self;
    	}
    	return self;
    }
    
    Thanks
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    Objects instantiated in Interface Builder are initialized at runtime using -initWithCoder:, not any arbitrary initializer you might have defined.
     
  3. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #3
    Ok thanks. BTW, "initWithContent" is specified in the API for NSTreeController.
     

Share This Page