Copy Selector Issue

Discussion in 'iPhone/iPad Programming' started by Sergio10, Jul 15, 2010.

  1. macrumors regular

    Joined:
    Oct 3, 2007
    #1
    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.
     
  2. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    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)
     
  3. thread starter macrumors regular

    Joined:
    Oct 3, 2007
    #3
    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.
     
  4. macrumors 6502

    seepel

    Joined:
    Dec 22, 2009
    #4
    You can also look at NSInvocation if you need to call a selector with arguments.
     
  5. macrumors 603

    Joined:
    Aug 9, 2009
    #5
    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
     

Share This Page