代码之家  ›  专栏  ›  技术社区  ›  ennuikiller

询问uibutton值时,为什么xcode调试器输出与我期望的不匹配?

  •  0
  • ennuikiller  · 技术社区  · 15 年前

    这个屏幕截图解释了这一切:

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

    (gdb)po((uibutton*)control).buttonType
    < /代码> 
    
    

    没有名为buttonType的成员。

    按要求:

    nslog(@“call out accessory tapped:set pincolor to red in call out accessory tapped”);
    nslog(@“调出抽头附件:uibuttontypetaildisclosure=%d”,uibuttontypetaildisclosure);
    nslog(@“调出附件抽头:控制按钮类型=%d”,((uibutton*)控制按钮类型);
    
    if(((uibutton*)控件).buttonType==2){
    nslog(@“________________
    leftCallout按钮。available=是;
    }
    

    if语句的计算结果为false!!试图理解为什么ButtonType被报告为2(如果事实是用类型2创建的)

    应迈克的要求:

    (gdb)p(int)[(uibutton*)control)buttonType]
    1美元=0美元
    2009年12月31日14:04:26.821 iparknow![4432:207]_________________
    (gdb)P(int)[(uibutton*)控件)按钮类型]
    < /代码> 
    
    

    好吧,这样做更有意义。现在的问题是,为什么按钮类型从2更改为0?它是用buttonType 2创建的,并不知何故更改为0。有什么想法吗??/P

    屏幕截图显示调试器报告按钮类型为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语句的计算结果为false!!试图理解为什么ButtonType被报告为2(如果事实是用类型2创建的)

    应迈克的要求:

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

    好吧,这样做更有意义。现在的问题是,为什么按钮类型从2更改为0?它是用buttonType 2创建的,并不知何故更改为0。有什么想法吗??

    1 回复  |  直到 15 年前
        1
  •  2
  •   Mike    15 年前

    _ ButtonFlags是一个私有实例结构。你不应该为此担心。唯一能“保证”如您所期望的那样工作的是公共API——实现细节可能会发生变化。

    (作为旁注,以_u开头的变量通常是一个私有实例变量)

    就你而言,试试看 p (int) [((UIButton *)control) buttonType] .

    您还可以考虑创建一个断点操作,以便在设置的断点记录所需的任何内容。见 http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeDebugging/200-Managing_Program_Execution/program_execution.html 了解更多详细信息。