NSObjet respondsToSelector:method does not work when the method has arguments.
NSObjet respondsToSelector:method does not work when the method has arguments.
- Subject: NSObjet respondsToSelector:method does not work when the method has arguments.
- From: "Bruce Wittenmyer" <email@hidden>
- Date: Fri, 30 Aug 2002 16:35:37 -0700
- Thread-topic: NSObjet respondsToSelector:method does not work when the method has arguments.
NSObject respondsToSelector:method does not work when the selector has
arguments.
=20
I'm using NSSelecorFromString to find a selector - that appears to work,
but then when I try to verify that selector exists using
respondsToSelector, it returns false. I can only get this to work if
the selector has no arguments.
Anyone know how verify selectors with arguments? What I'm doing wrong?
=20
I'm running on 10.2 with Aug updated tools.
=20
Thanks,
Bruce
=20
Simple code follows:
=20
#import <Cocoa/Cocoa.h>
=20
@interface MyClass : NSObject
{
}
- (IBAction)clickedButton:(id)sender;
- (void)foo1;
- (void)foo2:(id)theArgs;
=20
@end
=20
@implementation MyClass
=20
- (IBAction)clickedButton:(id)sender
{
=20
SEL method1;
SEL method2;
=20
method1 =3D NSSelectorFromString(@"foo1");
method2 =3D NSSelectorFromString(@"foo2");
=20
// ARG!!! Why doesn't this work? respondsToSelector does not find
the
// method if it has paramiters with it...
if ([self respondsToSelector:method1]) {
[self performSelector:method1];
} else {
NSLog(@"Not finding foo1");=20
}
=20
if ([self respondsToSelector:method2]) {
[self performSelector:method2 withObject:@"My cool args"];
} else {
NSLog(@"Not finding foo2");
}
}
=20
- (void)foo1 {
NSLog(@"Im in foo1");
}
=20
- (void)foo2:(id)nssArgs {
NSLog(@"Im in foo2 with param of %@",nssArgs);
}
=20
@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.