【问题标题】:iPhone UIButton buttonType always evaluates to 0?iPhone UIButton buttonType 总是评估为 0?
【发布时间】:2010-12-31 21:58:57
【问题描述】:

每当我执行下面的代码时,无论我为 buttonWithType 指定什么,我总是得到 button type = 0。有谁知道这种行为的解释?我试图根据按钮的类型来区分按钮显然没有成功,因为 buttonType 属性似乎已损坏(或无用)。一如既往,非常感谢您提供的任何启发!

UIButton *button = [[UIButton buttonWithType:UIButtonTypeDetailDisclosure] retain];
button.frame = frame;
NSLog(@"###################### LeftCalloutButtons - buttonWithTitle(73) - button type = %d",button.buttonType);

【问题讨论】:

    标签: iphone iphone-sdk-3.0 properties uibutton


    【解决方案1】:

    在将按钮添加到视图之前,我遇到了 UIButton 属性(在我的情况下为背景颜色)具有虚假值的情况。一旦按钮出现在屏幕上,请尝试查询属性。

    编辑:刚刚看到了这种行为的另一个例子。这次是关于 UISwitch.on。如果我在 alloc/init 之后立即将其设置为 YES,则它不会显示为 on。如果我在 viewDidLoad 处理程序中将其设置为 YES,它将按预期工作。

    显然 UIKit 中有一些延迟加载。

    【讨论】:

    • 当我在屏幕上查询详细信息披露按钮时,我仍然得到 0: 2010-01-02 22:06:12.973 iParkNow![2405:207] ####### ######### CALL OUT ACCESSORY TAPPED: control button type = 0
    【解决方案2】:

    我刚刚验证了 iOS 4.3.2 和 Xcode 4.0.2 的相同问题。在调试器中查看UIButton 实例的内部结构时,私有struct _buttonFlags 包含设置为正确值的unsigned int buttonType(在我的情况下为非零)。

    但是,调试器在响应print (int) [control buttonType] 时总是报告0

    总之,buttonType 方法已损坏,我将把它作为一个错误报告给 Apple。我认为,如果其他尝试使用此方法的人也这样做,也不会造成伤害。

    【讨论】:

      猜你喜欢
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      • 2019-09-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-24
      相关资源
      最近更新 更多