2

I just installed xcode 6 to test out how my app works with it.

The facebook login button on the initial page does not appear to be working.

Here is my code:

@property (nonatomic, strong) UIButton *loginButton;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.loginButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 70)];
    self.loginButton.center = self.view.center;
    [self.loginButton setImage:[UIImage imageNamed:@"login_fb.png"] forState:UIControlStateNormal];

    [self.view addSubview:self.loginButton];
    [self.loginButton addTarget:self action:@selector(loginButtonPressed) forControlEvents:UIControlEventTouchUpInside];
 }

-(void)loginButtonPressed
{
      // perform login
}

It is important to note that the app starts off on a different view. In that view controller I check to see if a user exists or not, and if not I present the login view. Here is that code:

 if ([DCTUserIdentity currentIdentity] == nil) {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    DCTInitialLoginVC *vc = [sb instantiateViewControllerWithIdentifier:@"InitialLogin"];
    vc.delegate = self;
    [self presentViewController:vc animated:NO completion:^{}];
}

I put a breakpoint in the loginButtonPressed function and it never gets hit when I try clicking on the button....any idea whats going on?

Atul Bhatia
  • 1,633
  • 5
  • 25
  • 50
  • Is that the entire code? Are there other subviews? Any gestures? What are the superviews? – Wain Sep 17 '14 at 22:39
  • This page has no gestures. The app starts off on a different page -- on that page I check to see if a user exists. If not, I present this view controller. The code I use for that is: if ([DCTUserIdentity currentIdentity] == nil) { UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]]; DCTInitialLoginVC *vc = [sb instantiateViewControllerWithIdentifier:@"InitialLogin"]; vc.delegate = self; [self presentViewController:vc animated:NO completion:^{}]; } – Atul Bhatia Sep 17 '14 at 22:45
  • I went ahead and pasted the code in the post as well to make it more readable – Atul Bhatia Sep 17 '14 at 22:46
  • What is the frame of the `self` view when you call `presentViewController` ? is it full screen? is the view 'under' where the button is on the presented view? – Wain Sep 17 '14 at 22:47
  • Yes it is full screen. I'm not sure I understand your 2nd question. – Atul Bhatia Sep 17 '14 at 22:56
  • Also I should add that I can see the loginButton show up on the login screen. It is just that nothing happens when I click it. – Atul Bhatia Sep 17 '14 at 23:02
  • The question relates to 'is the button able to handle touches'. Is some other view stealing them / blocking them (user interaction disabled)? – Wain Sep 17 '14 at 23:09
  • ah, that is a good thought. I put a breakpoint in viewWillAppear of the login view controller and did a check to see the value of self.view.userInteractionEnabled. It is set to true. – Atul Bhatia Sep 17 '14 at 23:15
  • The code works perfectly fine in xcode 5 (with ios 7) btw. It just appears to be causing issues when i use xcode 6 and ios 8. – Atul Bhatia Sep 17 '14 at 23:16
  • I found that using [self.navigationController pushViewController:vc...] actually fixes the issue...but now I still have the navigation tab at the top of my login view and a back button, which I don't want. I wonder why presentViewController makes it so I can't push any buttons? – Atul Bhatia Sep 17 '14 at 23:41
  • try presenting from the root view controller – Wain Sep 18 '14 at 08:07
  • Having the same problem as original poster. In my situation, I have a button in a cell of a UICollectionView. Button appears fine, but I can't press it. Was working fine in Xcode 5 but not Xcode 6.0.1. Target is iOS 7 for both. – Dalmazio Sep 24 '14 at 01:09

2 Answers2

0

It appears that this is not actually a bug, but an incompatibility issue of targeting iOS 7 devices using Xcode 6. ecotax's post describes this in more detail, but here is the response from Apple DTS:

In iOS 7, cells’ content views sized themselves via autoresizing masks. In iOS 8, this was changed, cells stopped using the autoresizing masks and started sizing the content view in layoutSubviews. If a nib is encoded in iOS 8 and then decode it on iOS 7, you’ll have a content view without an autoresizing mask and no other means by which to size itself. So if you ever change the frame of the cell, the content view won’t follow.

Apps being deploying back to iOS 7 will have to work around this by sizing the content view itself, adding autoresizing masks, or adding constraints.

Workaround:

- (void)awakeFromNib
{
   // Fix for iOS 7 devices targeted using Xcode 6.
   self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
Community
  • 1
  • 1
Dalmazio
  • 1,835
  • 2
  • 23
  • 40
  • 1
    I am seeing the issue when running the app on an ios 8 simulator via xcode 6. I don't think your comment applies to that situation. Again, the button shows up find, but I can't click on it. For what it's worth I tried your solution by replacing contentView with the view for my button but it didn't work. – Atul Bhatia Sep 24 '14 at 10:48
  • Not sure about the iOS 8 simulator issue. Admittedly, this solution solves the problem for a cell (which contained buttons that weren't clickable) in a collection view. `contentView` in this context is the content view of the cell. So your issue *may* be different, but they look awfully similar. In any case, you might want to try simply overriding `awakeFromNib` for the view in which your button resides, and setting the autoresizing mask as given. Also, refer to the original link, as some posts there include a line to set the view bounds first, which wasn't necessary in my situation. – Dalmazio Sep 24 '14 at 19:40
0

Try this code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.loginButton.frame = CGRectMake(0, 0, 200, 70);
    self.loginButton.center = self.view.center;
    [self.loginButton setImage:[UIImage imageNamed:@"login_fb.png"]
                      forState:UIControlStateNormal];

    [self.view addSubview:self.loginButton];
    [self.loginButton addTarget:self action:@selector(loginButtonPressed:)     
               forControlEvents:UIControlEventTouchUpInside];

}

And hold your DCTInitialLoginVC object with strong pointer.

arturdev
  • 10,884
  • 2
  • 39
  • 67