PDA

View Full Version : Copy Selector Issue




Sergio10
Jul 15, 2010, 11:25 AM
Hi,

How correctly copy selectors?
Does it correct way:

- (void)viewDidLoad {

[self someMethod:@selector(viewDidLoad)];
}

- (void)someMethod:(SEL)selector {

SEL selector_2 = selector; // is it correct??
[self performSelector:@selector(selector_2)];
}


Thanks.



iSee
Jul 15, 2010, 11:56 AM
The problem isn't with copying the selector, its with how you are using the copy. Try this (note change on last line):

- (void)viewDidLoad {

[self someMethod:@selector(viewDidLoad)];
}

- (void)someMethod:(SEL)selector {

SEL selector_2 = selector; // is it correct??
[self performSelector: selector_2];
}


(not to mention the infinite loop)

Sergio10
Jul 18, 2010, 06:10 AM
Now it's working. Thanks.

1. How can I run method by selector without knowing pointer to class where it calls?
Because in previous case I used "self" pointer which means called method is placed in current class.

2. Should I release selectors?

Thank you.

seepel
Jul 18, 2010, 06:20 AM
You can also look at NSInvocation if you need to call a selector with arguments.

chown33
Jul 18, 2010, 11:34 AM
Now it's working. Thanks.

1. How can I run method by selector without knowing pointer to class where it calls?
Because in previous case I used "self" pointer which means called method is placed in current class.

2. Should I release selectors?

Thank you.

1. You can't run a method by selector without knowing which object to run it on. If you need an object other than self, then you must pass that object in some way.

2. Follow the memory management rules.
http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html