Re: Selector Not Recognized
Re: Selector Not Recognized
- Subject: Re: Selector Not Recognized
- From: David Alter <email@hidden>
- Date: Tue, 11 Jul 2006 15:30:03 -0700
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
On Jul 11, 2006, at 3:02 PM, Shawn Erickson wrote:
On 7/11/06, David Alter <email@hidden> wrote:
I have a sub class of an object. The sub class has no additional
instance variables, just some additional methods. I get a pointer to
the parent object and I want to call methods available in the sub
classed objects. So I tried to case it and make the call. To this I
get "selector not recognized". Is there a way to do this? I can do
this in C++.
Sorry not understanding you fully... oh and please start class names
with upper case letters. :)
Example bellow if needed
@interface myParent : NSObject {
int somedata
}
- (int) getSomeDataPlusOne; //
@end
In the main body of code
myParent * myObj = [[myParent alloc] init];
mySub * mysub = (mySub *) myObj;
int val = [mysub getSomeDataPlusOne]; // It chokes here with
"selector not recognized"
Now you have me even more confused (omitted to much context)... :)
Is "myParent" class the super class of "mySub" class? ...and you want
a method implemented by "mySub" class to call a method provided by
"mySub" superclass?
If so note you can message "super"...
@interface SuperClass : NSObject {
}
- (void) doThis;
@end
@interface SubClass : SuperClass {
}
- (void) doThat;
@end
@implementation SubClass
- (void) doThat
{
[super doThis];
}
-Shawn
_______________________________________________
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