iphone - UIButton 方法在 Iphone 上调用但在 Ipad 上不调用

标签 iphone ios objective-c ipad uibutton

我正在实现一个通用应用程序。我在这样的 init 方法中实现了一个“UIView”:

[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];

但是当我添加一个“UIButton”时,它在 Iphone 模拟器上运行,而不是在 Ipad 模拟器上运行。

请参阅,在“ViewDidLoad”方法中:

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];

请问如何解决?

最佳答案

确保您的项目配置为构建“通用”应用。在 iPad 上运行的 iPhone 应用程序仍会将其 UI 习惯用法标识为“iPhone”。

关于iphone - UIButton 方法在 Iphone 上调用但在 Ipad 上不调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18792469/

相关文章:

objective-c - 使用 NSInputStream 读取动态增长的文件

iphone - 哪些类可以用作 NSDictionary 中的键?

iphone - 从本地 war 文件夹加载 html 文件

iphone - UIImagePickerController 覆盖 View 和显示相机控件问题

iphone - SDWebImage清除缓存

ios - AFNetworking 2 - 请求失败时没有响应正文

iphone - 使用相机拍摄多张照片时,如何检查是否有足够的内存来处理 UIImagePickerController 捕获的图片?

ios - Braintree 嵌入式 UI (iOS)

ios - 具有默认 nil 值的 UIDatePicker - iOS

ios - 通过对具有匹配 ID 号的对象进行分组来重建 NSArray?