Execute loadView for iPhone only in Universal application

74 views Asked by At

I am currently porting iPhone app to iPad application. Now in few screens of iPhone app all the UI is done via code with Visual Format Language. Now in iPad since UI is different I can simply do it via Interface Builder. Now how can I my app execute the loadView for iPhone app only & not for iPad ?

I tried below option

#define IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone

#ifndef IS_IPHONE
- (void)loadView
{
    self.myView = [[MyCustomView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.view = self.myView;
}
#endif

- (void)viewDidLoad
{
    // my other code 
}

But for iPhone loadView is not getting called. Directly viewDidLoad method is executed.

Can anyone tell me how can I achieve this ? Thanks in advance.

1

There are 1 answers

1
Franck On

You can do someting like this :

#define IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone   

- (void)loadView {
    if (IS_IPHONE)
    {
        self.myView = [[MyCustomView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        self.view = self.myView;
    }
    else {
        //other code
    }
}