【问题标题】:Why does the XCode debugger output not match what I expect, when interrogating UIButton values?为什么在询问 UIButton 值时 XCode 调试器输出不符合我的预期?
【发布时间】:2009-12-31 18:11:35
【问题描述】:

这张截图说明了一切:

屏幕截图显示调试器报告 buttonType 为 2,但控制台显示按钮类型 = 0。调试器和控制台中显示了相同的变量。知道这种不匹配是如何发生的吗?

(gdb) po ((UIButton *)control).buttonType

没有名为 buttonType 的成员。

根据要求:

    NSLog(@"################ CALL OUT ACCESSORY TAPPED: set pinColor to RED in call out accessory tapped");
    NSLog(@"################ CALL OUT ACCESSORY TAPPED: UIButtonTypeDetailDisclosure = %d",UIButtonTypeDetailDisclosure);
    NSLog(@"################ CALL OUT ACCESSORY TAPPED: control button type = %d", ((UIButton *)control).buttonType);

    if (((UIButton *)control).buttonType == 2) {
        NSLog(@" ############# CALL OUT ACCESSORY TAPPED: in buttonType = disclosure");
        leftCallOutButton.available = YES;
    }

if 语句的计算结果为假!!试图理解为什么 buttonType 被报告为 2 (如果 fact 是用 type 2 创建的)

根据 Mike 的要求:

(gdb) p (int) [((UIButton *)control) buttonType]
$1 = 0
2009-12-31 14:04:26.821 iParkNow![4432:207] ################ CALL OUT ACCESSORY TAPPED: control button type = 0
(gdb) p (int) [((UIButton *)control) buttonType]

好的,所以这更有意义。现在的问题是为什么 buttonType 会从 2 变为 0?它使用 buttonType 2 创建并以某种方式更改为 0。有什么想法吗??

【问题讨论】:

  • @ennukiller:您能否给我们来自NSLog() 调用的代码,该调用输出“UIButtonTypeDetailDisclosure = 2”到输出“控制按钮类型 = 0”的NSLog() 调用,包括这两行?这可能会有所帮助。
  • @John,根据您的要求发布。
  • @ennukiller:你试过运行我修改后的命令吗?可以发一下结果吗?
  • @ennukiller,我想你的意思是我。命令是p (int) [((UIButton *)control) buttonType]
  • @ennukiller:谢谢。非常有趣,起初我以为我发现了它,然后我意识到我的错误。我发现有趣的是po ((UIButton *)control).buttonType 在(在您的断点处)您已经执行了完全相同的代码行时没有找到这样的成员。 po control 呢?诚然,这将是大量无关的数据,但它可能会提供更多洞察力。

标签: objective-c xcode debugging


【解决方案1】:

_buttonFlags 是一个私有实例结构。你不应该担心它。唯一可以“保证”按您预期工作的是公共 API - 实施细节可能会发生变化。

(附带说明,以 _ 开头的变量通常是私有实例变量)

在您的情况下,请尝试p (int) [((UIButton *)control) buttonType]

您还可以考虑创建一个断点操作以在您设置的断点处记录您想要的任何内容。详情请见http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeDebugging/200-Managing_Program_Execution/program_execution.html

【讨论】:

  • 好的,那我该如何在调试器中查看buttonType的值呢?
  • @Mike,请在我的问题中打印对象的结果。它无法解析该变量。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-31
  • 2015-09-16
相关资源
最近更新 更多