Re: Selector Not Recognized
Re: Selector Not Recognized
- Subject: Re: Selector Not Recognized
- From: Chris Suter <email@hidden>
- Date: Wed, 12 Jul 2006 08:40:54 +1000
On 12/07/2006, at 8:30 AM, David Alter wrote:
Sorry about that. That was not the example I intended to send. Lets
see if this does a better job of explaining this.
//The interface for the parent class
@interface MyParent : NSObject {
int somedata
}
@end
//The interface for the sub class
@interface MySub : MyParent {
}
- (int) getSomeDataPlusOne; // This will access somedata from the
parent class add one to it and return it.
@end
//Some code some place
//Make an instance on MyParent
MyParent * parent = [[MyParent alloc] init];
//Cast MyParent into a pointer of MySub.
MySub * sub = (MySub *) parent;
//Access a method of MySub.
int val = [sub getSomeDataPlusOne]; // It chokes here with
"selector not recognized"
The key here is the pointer is a pointer to MyParent, NOT MySub.
Sense MySub has not instance variables can I cast it into MyParent.
If not what is the suggested way of doing things.
Thanks again for the help
-dave
All objective-C calls are resolved at runtime. Casts don't make any
difference to which methods get called.
If you want to override a method in an existing class you can use
categories or poseAsClass. Read the documentation for poseAsClass in
NSObject.
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden