missing keyword?

Discussion in 'Mac Programming' started by kevinrichardsuk, Jun 17, 2008.

  1. macrumors member

    Joined:
    May 19, 2008
    #1
    I need to send an integer back to my AppDelegate instance, from a class instance created by it.

    Code:
    [AppDelegate setNumber:1];
    This presumes the method in AppDelegate is +(void)setNumber and hence won't allow access to my instance variables. I understand I'm sending a message to AppDelegate and not an instance of it..

    Am I missing a keyword (such as self) to access the instance of AppDelegate?

    Thanks
     
  2. macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #2
    As I understand it, you're trying to send a message to the AppDelegate class object from an AppDelegate instance.

    Your code above is fine, but I would consider the following best practise:

    Code:
    [[self class] setNumber:1];
     
  3. thread starter macrumors member

    Joined:
    May 19, 2008
    #3
    Thanks for the reply. I'll try and explain a bit better..

    I've created an instance of a custom UIView (called TestView) from the AppDelegate instance. I've added a subview to that view, which can be pressed.

    The press event triggers -(void)touchesBegan in my TestView instance, I need to pass [touch view] back to my AppDelegate instance for processing, but I don't know how to reference my instance of AppDelegate, only the class object..
     
  4. macrumors 6502

    Joined:
    Mar 31, 2005
    Location:
    London, England
    #4
    It sounds like you should be subclassing UIControl rather than UIView. UIControl has a target/action facility which allows controllers to register for callbacks messages (actions) when the user interacts with the control.

    Otherwise, you could pass the AppDelegate instance to your view using a custom init method, and keep it around as an instance variable, but this is not good design, as it creates an unnecessary dependency between the view object and the controller.
     
  5. thread starter macrumors member

    Joined:
    May 19, 2008

Share This Page