Do IBAction methods have scope?

Discussion in 'Mac Programming' started by nutthick, Aug 5, 2008.

  1. nutthick macrumors newbie

    Joined:
    Apr 11, 2007
    #1
    I have a small application running out of a single class. It's not ideal, but I'm still learning. In the header of my class I have a NSMutableArray defined, that I manipulate in the .m file.

    I have connected the open menu of my nib to an IBAction, that brings up an openPanel, with the selector defined as another method in my class. In that method I use the following call;

    Code:
    [myArray removeAllObjects];
    The strange thing is that I can have any number of objects in the array, but when I put in a break point on this line it says that there are 0 objects. This is before the line is run. After the line is executed it still say 0 as you would expect. However when the application continues elsewhere, all the objects are back in the array.

    The only thing I can think of is that the compiler is treating this instance of myArray as something different to the rest of the class, hence my question about scope.

    To test this out I tried setting a BOOL flag and calling the removeAllObjects elsewhere in the code, based on it, but the same thing happens with the flag. I set it in the selector method but it is different to the instance in the rest of the class.

    Can anyone explain this behaviour to me? Is this because I'm not using a MVC architecture?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Make sure you don't have multiple instances of that class being initialized. You could override init to check.
     
  3. nutthick thread starter macrumors newbie

    Joined:
    Apr 11, 2007
    #3
    In my NIB I have a custom view that I have set to my class (don't have XCode in front of me and can't remember the correct term) in the attribute inspector. I also have a NSObject that is set to my class that the menu items connect to. Would that end up creating two instances of the class?
     
  4. nutthick thread starter macrumors newbie

    Joined:
    Apr 11, 2007
    #4
    kainjow - You were right, I was creating two instances. I re-architected the app to be a proper MVC and that sorted out the multiple instance problem.

    Thanks for your help, this has been driving me nuts.
     

Share This Page