Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kevinrichardsuk

macrumors member
Original poster
May 19, 2008
30
0
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
 

Nutter

macrumors 6502
Mar 31, 2005
432
0
London, England
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];
 

kevinrichardsuk

macrumors member
Original poster
May 19, 2008
30
0
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];

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..
 

Nutter

macrumors 6502
Mar 31, 2005
432
0
London, England
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.