2

I don't know if it's possible for me to include code here that's relevant as my project is so large but are there any typical reasons why NSLog would repeat some warnings and calls to it at occasions where only one call/error is occuring?

As an example, I have a subclass of NSBox that inits an instance of another class on awakeFromNib:

- (void) awakeFromNib {
    burbControllerInstance = [[BurbController alloc] init];
    if (burbControllerInstance) {
        NSLog(@"init ok");
    }
}

I get NSLog printing "init ok" twice. I don't see why this subclass would be 'awoken' twice anywhere in my project. This is part of a larger problem where I can't get variables to return anything but nil from the class I'm creating an instance of. I'm wondering if perhaps the double values are something to do with it.

jscs
  • 63,694
  • 13
  • 151
  • 195
biscuitstack
  • 11,591
  • 1
  • 26
  • 41
  • Are you deriving from that class? – Sebastian Apr 30 '11 at 19:50
  • Define deriving. As in, retrieving variables? No, I am calling a method in the BurbController class that alters a bunch of variables only relevant to that class. They hold correct data when the method is run inside its own class but hold 'nil' when I call the method from my NSBox subclass. – biscuitstack Apr 30 '11 at 20:03
  • No, I don't believe I am. I've subclassed `NSbox` for only one object in my interface and I've only overruled methods relating to printing and pagination for `NSBox` in this one object. I don't see where else it would be awoken twice on the application starting up. – biscuitstack Apr 30 '11 at 20:31

1 Answers1

3

This post could be helpful, i. e. one comment:

Also important: awakeFromNib can be called multiple times on the controller if you use the same controller for several nibs – say, you’re using the app delegate as the owner of both the app’s About Box and preferences dialog. So you’ll need an extra guard test if you use awakeFromNib for anything but initializing the nib objects

Update: Much more interesting could also be this, where the author mentions that awakeFromNib gets called twice. Unfortunately there is no real answer for this particular problem but maybe some basic ideas.

Update #2: Another potential solution from stackoverflow.com: View Controller calls awakeFromNib twice.

Community
  • 1
  • 1
Sebastian
  • 8,046
  • 2
  • 34
  • 58
  • Aha, the last link helped a lot. It gave the idea that I didn't need to initialise my subclass through the nib palette, as I usually do. So what was happening was the nib was being started by my object in my interface and also in the nib palette. It was a bad habit I'd picked up. Thankyou! Now onto figuring out why my variables still don't return values.... – biscuitstack Apr 30 '11 at 22:12
  • 1
    @biscuitstack: Ok, that was also the intention when i was asking about deriving from that class. Usual in this case multiple objects were initialized. – Sebastian May 01 '11 at 06:36
  • Gotcha. Thanks, I'm still not at this that long so sometimes only catch onto things when they're spelt out a little more specifically. – biscuitstack May 01 '11 at 11:14
  • No problem, especially large projects are sometimes somewhat difficult. – Sebastian May 01 '11 at 11:50