user2057209
user2057209

Reputation: 345

UIButton method called on Iphone but not Ipad

I'm implementing an universal application. I implement a 'UIView' in the init method like this :

[self setWantsFullScreenLayout:YES];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    Menu = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
    [Menu setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Fond_Menu.png"]]];
}
else
{
   Menu = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 768, 1024)];
   [Menu setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Fond_Menu_Ipad.png"]]];
}
[self.view addSubview:Menu];
[Menu release];

But when i add a 'UIButton', it works on Iphone simulator and not in Ipad one.

See, in 'ViewDidLoad' method :

Jouer = [UIButton buttonWithType:UIButtonTypeCustom];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    [Jouer setFrame:CGRectMake(82.5, 240, 155, 35)];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer", @"")] forState:UIControlStateNormal];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer_HIGH", @"")] forState:UIControlStateHighlighted];
}
else
{
    [Jouer setFrame:CGRectMake(214, 505, 340, 77)];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer_Ipad", @"")] forState:UIControlStateNormal];
    [Jouer setImage:[UIImage imageNamed:NSLocalizedString(@"Bouton_Jouer_HIGH_Ipad", @"")] forState:UIControlStateHighlighted];
}
[Jouer addTarget:self action:@selector(MyMethod)forControlEvents:UIControlEventTouchUpInside];
[Menu addSubview:Jouer];

How to fix it please ?

Upvotes: 3

Views: 604

Answers (3)

user2057209
user2057209

Reputation: 345

Fixed !

I forget to make a difference between iPhone and Ipad into the delegate, so the main window was in iPhone format =)

Upvotes: 0

David Doyle
David Doyle

Reputation: 1716

Check the images you're setting on the button - if one of the iPad ones is nil this could cause your button not to be displayed properly. If its not that, check your button actions implementation.

Upvotes: 0

thatzprem
thatzprem

Reputation: 4767

Make sure that your project is configured to build a "Universal" app. An iPhone app running on the iPad will still identify its UI idiom as "iPhone".

Upvotes: 3

Related Questions