Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Make sure...</p> <ol> <li>Button is placed in root view in <code>xib</code> as you are finding it in <code>self.view</code> OR make sure it is placed in correct view and use that view with <code>viewWithTag</code></li> <li>You have assigned tag <strong>1</strong>, so just make sure no other control within same view have tag 1 other wise button will not be recognized by tag. If this is going to be your case then just change tag of button to very unusual number for that view like 999 or any thing else and test.</li> </ol> <p><strong>EDIT</strong></p> <p>I am feeling like you view is not getting recognized at <code>viewDidLoad</code> where you have setup your code. So just comment out that code in <code>viewDidLoad</code> and shift in your <strong>changeOrientation</strong> method after loading nib.</p> <pre><code>-(void)changeOrientation { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if(orientation==UIInterfaceOrientationPortrait || orientation==UIInterfaceOrientationPortraitUpsideDown) { [[NSBundle mainBundle] loadNibNamed:@"PortraitXib" owner:self options:nil]; } else { [[NSBundle mainBundle] loadNibNamed:@"LandscapeXib" owner:self options:nil]; } //Adding this code here makes sense that nib is loaded and after that we are recognizing button from loaded view of nib. UIButton *btn = (UIButton*)[self.view viewWithTag:1]; [btn addTarget:self action:@selector(BtnClick:) forControlEvents:UIControlEventTouchUpInside]; } </code></pre> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload