Reputation: 524
I want to differentiate the controller for iPhone and iPad.
#ifdef __IPHONE_NA
{
UINavigationBar *ipadNavBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 768.0f, 50.0f)];
[[self view] addSubview: ipadNavBar];
UINavigationItem *ipadNavItem = [[UINavigationItem alloc] initWithTitle: @"EMPLOYEE"];
[ipadNavBar pushNavigationItem:ipadNavItem animated:NO];
}
else
{
UINavigationBar *ipadNavBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 360.0f, 45.0f)];
[[self view] addSubview: ipadNavBar];
UINavigationItem *ipadNavItem = [[UINavigationItem alloc] initWithTitle: @"EMPLOYEE"];
[ipadNavBar pushNavigationItem:ipadNavItem animated:NO];
}
if saying error unterminated #ifdef
Is this approach correct?
Upvotes: 9
Views: 2529
Reputation: 4409
if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) {
Console.WriteLine("Phone");
} else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
Console.WriteLine("Pad");
}
Upvotes: 0
Reputation:
You can make use of the constants already present:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
// Some code for iPhone
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// Some code for iPad
}
Naturally you wouldn't need the else if
statement, you could just use else
however I'm just using it illustrate the difference constants available.
You can find out more here (look at the section on UI_USER_INTERFACE_IDIOM
).
Upvotes: 17
Reputation: 4276
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
NSLog(@"iPad Idiom");
else
NSLog(@"iPhone Idiom");
Upvotes: 2