title: IOS UIBarButtonItem works fine while UIButton causes Unrecognized Selector Sent to Instance
body: <p>I am trying to implement a custom navigation bar button item, I have a selector when user clicks to bar item a function is called.
  If I set bar item to <code>UIBarButtonItem</code> it just works fine but I have to use a custom Image for the button without borders and appropriated size.</p>
  
  <p>so in viewdidload I call </p>
  
  <pre><code>- (void)viewDidLoad 
  {
      [super viewDidLoad];
      //gear button on navigation Bar
      UIImage* imageback2 = [UIImage imageNamed:@"ICON - Gear-BarstyleItem@2x.png"];
      CGRect frameimgback2 = CGRectMake(0, 0, 40, 40);
  
      UIButton *backButton2 = [[UIButton alloc] initWithFrame:frameimgback2];
      [backButton2 setBackgroundImage:imageback2 forState:UIControlStateNormal];
      [backButton2 addTarget:self
                      action:@selector(setColorButtonTapped:)
            forControlEvents:UIControlEventTouchUpInside];
  
      UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithCustomView:backButton2];
  
  
      UIBarButtonItem *btn3 =[[UIBarButtonItem alloc] initWithImage:imageback2 style:UIBarButtonItemStylePlain target:self action:@selector(setColorButtonTapped:)];
  
      self.navigationItem.rightBarButtonItem = btn2;
  }
  
  #pragma mark Callbacks
  
  - (IBAction)setColorButtonTapped:(id)sender{
      if (_colorPicker == nil) {
          self.colorPicker = [[ColorPickerController alloc] initWithStyle:UITableViewStylePlain];
          _colorPicker.delegate = self;
          self.colorPickerPopover = [[UIPopoverController alloc] initWithContentViewController:_colorPicker];
      }
      [self.colorPickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  }
  </code></pre>
  
  <p>this gives me:</p>
  
  <pre><code>-[UIButton view]: unrecognized selector sent to instance 0x9466620
  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton view]: unrecognized selector sent to instance 0x9466620'
  </code></pre>
  
  <p>If I set </p>
  
  <pre><code> self.navigationItem.rightBarButtonItem = btn2;
  </code></pre>
  
  <p>to</p>
  
  <pre><code> self.navigationItem.rightBarButtonItem = btn3;
  </code></pre>
  
  <p>It works fine but button have borders and background color and smaller size of image</p>
  
  <p>So why it gives me error and how can I make this button a custom button?</p>
  
  <p>Edit:</p>
  
  <p>When I add a void function like </p>
  
  <pre><code>- (void)gearTapped{
      [self setColorButtonTapped:self];
  }
  </code></pre>
  
  <p>and change selector at button it does not give any error but it shows popUp only one line an in the middle of the screen</p>
  
  <pre><code>[backButton2 addTarget:self
                      action:@selector(gearTapped)
            forControlEvents:UIControlEventTouchUpInside];
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/CTeBj.png" alt="enter image description here"></p>
  
  <p>It normally should work like this but with an custom button
  <img src="https://i.stack.imgur.com/lvKlp.png" alt="enter image description here"></p>