【问题标题】:How to manage a BOOL variable?如何管理 BOOL 变量?
【发布时间】:2013-10-28 21:59:52
【问题描述】:

我正在使用变量“音量”

@property BOOL * volume;

设置音量开 (YES) 或关 (NO)

- (IBAction)manageVolume:(UIButton *)sender {
    if (_volume == TRUE) {
        _volume = !_volume; 
//      code...
    } else {
        _volume = !_volume;
//      code...
        }
    }

它有效,但它返回三个警报:

  • if (_volume == TRUE) { 返回Comparison between pointer and integer ('BOOL *' (aka 'signed char *') and 'int')

  • _volume = !_volume; 返回Incompatible integer to pointer conversion assigning to 'BOOL *' (aka 'signed char *') from 'int'

我该如何解决?谢谢!

【问题讨论】:

    标签: ios objective-c int boolean


    【解决方案1】:

    您的属性定义错误。它不应该是指向BOOL 的指针,而应该只是BOOL

    @property BOOL volume;
    

    【讨论】:

    • 对!非常感谢!
    • 另外值得一提的是,适当的 BOOL 值包括YESNO,而不是truefalse。您应该看到 this thread 了解为什么这很重要。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多