-2

I have a UIView subclass ( PopupView ) and two xbis for it: PopupView.xib and PopupView~iphone5.xib .

When I call the xib:

    if ( screenHeight >= 568 ) {
        subviewArray = [[NSBundle mainBundle] loadNibNamed:@"PopupView~iphone5" owner:self options:nil];
    } else {
        subviewArray = [[NSBundle mainBundle] loadNibNamed:@"PopupView" owner:self options:nil];
    }

In iOS 7 when testing with 3.5inch phone it loads the correct PopupView.xib and with 4inch phone it loads PopupView~iphone5.xib. But when testing with iOS 6 and 3.5 inch phone, althought the code passes from the "else" statement and theoritically it loads the PopupView.xib , it actually returns the iphone 5 xib ( the view diplayed is the one designed for iphone5 ) and the loaded view's height is 548, not 480.

Any suggestions?

Panos
  • 7,227
  • 13
  • 60
  • 95
  • 568 >= 548 returns the same value as 568 >= 568. – nhgrif Jun 28 '14 at 12:30
  • Rather then guessing and making theoretical conjectures as to which execution path is followed, can you please just use log statements or a breakpoint? Also, I can only guess that the way you're calculating `screenHeight` perhaps doesn't work right for iOS 6, so include that code. – nhgrif Jun 28 '14 at 12:32
  • @Ramdy you are right, it was my typo, but 568 ( iphone 5 screen height ) is >= for both 548 and 568 values. So this does not solve the case. – Panos Jun 28 '14 at 12:32
  • @nhgrif Iam not guessing. I have checked it with the debugger and yes the code loads the part inside the else statement. This part is called: subviewArray = [[NSBundle mainBundle] loadNibNamed:@"PopupView" owner:self options:nil]; but still loads the iphone5 xib – Panos Jun 28 '14 at 12:34
  • How are you determining it is loading the incorrect xib? – nhgrif Jun 28 '14 at 12:36
  • @nhgrif I have a different design for iphone5. Actually this view is a "fullsize" view and has different sizes in some labels and a webview. So it is easy to understand which xib was loaded – Panos Jun 28 '14 at 12:37
  • What if you give your nibs completely different names? Try to not use the ~iphone5. Just randomNameA someOtherNameB. – nhgrif Jun 28 '14 at 12:40
  • @nhgrif I tried it. Still the same issue. Now my xib for iphone5 is called PopUpViewForIphone5 – Panos Jun 28 '14 at 12:58
  • pfff I fixed it. All I needed was to Clean Full build and also delete the app from the simulator and rebuild. – Panos Jun 28 '14 at 13:07

2 Answers2

0

Fixed. All I needed was to Clean Full build and also delete the app from the simulator and rebuild. Hope this case helps someone other who faces a similar problem and does not remember to clean his project.

Panos
  • 7,227
  • 13
  • 60
  • 95
-2

Try using following code.

-(id) init{
    UIScreen* mainscr = [UIScreen mainScreen];
    CGSize screenSize = mainscr.currentMode.size;
    CGFloat screenHeight = screenSize.height;
    if (screenHeight == 1136) {
        self = [super initWithNibName:@"PopupView~iphone5" bundle:[NSBundle mainBundle]];
    }
    else
    {
        self = [super initWithNibName:@"PopupView" bundle:[NSBundle mainBundle]];
    }
}

It is working for me.

Viral Narshana
  • 1,855
  • 2
  • 21
  • 45
  • as I said... the code gets in the Correct place of the if-else statement. The loadNibNamed works wrong. Also Iam not loading a UIViewController, but a UIView – Panos Jun 28 '14 at 12:39