title: How can I pas another object's function as a selector in IOS?
body: <p>I've read <a href="https://stackoverflow.com/questions/14083763/selector-as-parameter-in-ios">selector as parameter in IOS</a> post. However, I want to extend the question.</p>
  
  <p>In my case, I'm creating an Objective-C (not Swift) Master/Detail application, and want to create DetailController object of type UIViewController with the following init function</p>
  
  <p>In DetailViewController.h</p>
  
  <pre><code>@interfact DetailViewController : UIViewController
  - (id)initWithNibName:(NSString *)nibName withSaveSelector:(SEL)saveSelector
  @end
  </code></pre>
  
  <p>... and in DetailViewController.m</p>
  
  <pre><code>- (id)initWithNibName:(NSString *)nibName withSaveSelector:(SEL)saveSelector
  {
    self = [super initWithNibName:nibName bundle:nil];
    if (self) {
          UIBarButtonItem *done = [[UIBarButtonItem alloc]
                                   initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                   target:self
                                   action:saveSelector];
          [[self navigationItem] setRightBarButtonItem:done animated:YES];
    }
    return self;
  }
  </code></pre>
  
  <p>NOW, I want to just keep re-using above code to create different DetailViewControllers, and want to pass a saveSelector function that will get called when the user presses the "Done" button.</p>
  
  <p>Now I have another view controller</p>
  
  <pre><code>@interface AnotherViewController : UIViewController
  - (void)saveSelector:(id)sender;
  @end
  </code></pre>
  
  <p>...and then in yet another object (i.e., <strong>NOT in AnotherViewController.m code</strong>), I use the above view controller, like so...</p>
  
  <pre><code>AnotherViewController *avc = [[AnotherViewController alloc] init];
  DetailViewController *dvc = [[DetailViewController alloc] initWithNibName:@"AnotherViewController" withSaveSelector:@selector(???)];
  </code></pre>
  
  <p>What should I put in the ??? so I can pass AnotherViewController::saveSelector() function to DetailViewController?</p>
  
  <p>I hope that makes sense.</p>