【问题标题】:UIButton method called on Iphone but not Ipad在 Iphone 上调用 UIButton 方法,但不在 Ipad 上调用
【发布时间】:2013-09-18 12:06:40
【问题描述】:

我正在实现一个通用应用程序。我在 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];

请问如何解决?

【问题讨论】:

    标签: iphone ios objective-c ipad uibutton


    【解决方案1】:

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

    【讨论】:

    • 它被配置为一个通用应用程序,这就是我不明白的原因!我在创建 UIViewcontrollers 时没有选中“Targeted for ipad”复选框,但我看到没有链接
    【解决方案2】:

    检查您在按钮上设置的图像 - 如果其中一个 iPad 为 nil,这可能会导致您的按钮无法正确显示。如果不是,请检查您的按钮操作实现。

    【讨论】:

    • 图片效果很好,方法是正确的,因为它适用于iphone版本
    【解决方案3】:

    已修复!

    我忘记在代理中区分 iPhone 和 Ipad,所以主窗口是 iPhone 格式 =)

    【讨论】:

    • 您能解释一下这些差异吗?我目前面临同样的问题,但我的方法适用于 iPad 而不是 iPhone。
    猜你喜欢
    • 2015-12-31
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 2012-01-30
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    相关资源
    最近更新 更多