In my view controller, my view is initialized in loadView method:
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self loadViewController];
[self.view setBackgroundColor:[UIColor whiteColor]];
}
The loadViewController method creates a button and adds it to the view. Here's a snippet from the loadViewController method that initializes and positions the button:
graphicalButton = [UIButton buttonWithType:UIButtonTypeCustom];
graphicalButton.exclusiveTouch = YES;
[graphicalButton setImage:kGraphicalIconSelected
forState:UIControlStateSelected];
[graphicalButton setImage:kGraphicalIconDeSelected
forState:UIControlStateNormal];
[graphicalButton setFrame:CGRectMake(230, 100, 37, 34)];
[graphicalButton addTarget:self
action:@selector(graphicalOptionAction:)
forControlEvents:UIControlEventTouchUpInside];
[graphicalButton setUserInteractionEnabled:NO];
NSLog(@"graphical button x %f",graphicalButton.frame.origin.x);
[self.view addSubview:graphicalButton];
This displays the button correctly on an iPhone 4s simulator. The log statement logs the origin correctly as well.
However, on an iPhone 6 simulator, the log statement always logs the origin.x
as 0. The button does not get displayed if the code runs. If however, I set up a breakpoint at the beginning of this code snippet and then step through each line, it logs the origin.x
correctly and the button is displayed even on an iPhone 6 simulator.
I have even tried adding the call to loadViewController
in viewWillAppear
method, but even there the same issue occurs with this button. Any ideas on why this happens and how to resolve this?