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

Sergio10

macrumors regular
Original poster
Oct 3, 2007
137
0
Hi,

How correctly copy selectors?
Does it correct way:
PHP:
- (void)viewDidLoad {

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

- (void)someMethod:(SEL)selector {

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

Thanks.
 
The problem isn't with copying the selector, its with how you are using the copy. Try this (note change on last line):
Code:
- (void)viewDidLoad {

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

- (void)someMethod:(SEL)selector {

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

(not to mention the infinite loop)
 
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.
 
You can also look at NSInvocation if you need to call a selector with arguments.
 
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/libr...a/Conceptual/MemoryMgmt/Articles/mmRules.html
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.