在通知处理程序方法中,我设置了一个 BOOL 属性(isNotificationCarryingObject),如下所示:
-(void)notificationReceived:(NSNotification *)notification
{
//set flag depending upon if notification carries an object
//I tried following:
//1.
self.isNotificationCarryingObject = notification.object != nil;
//result: self.isNotificationCarryingObject = nil
//2.
self.isNotificationCarryingObject = notification.object != nil ? YES : NO;
//result: self.isNotificationCarryingObject = nil
//3.
self.isNotificationCarryingObject = YES;
//result: self.isNotificationCarryingObject = YES ?????
}
使用 1. 和 2. 我无法设置标志,但使用 3. 它设置为 YES,我不明白为什么?根据我的说法,所有 3 个陈述都应该有效。
isNotificationCarryingObject 属性定义为:
@property (nonatomic, assign) BOOL isNotificationCarryingObject;
通知处理程序位于呈现 View Controller 内。呈现的 View Controller 在其 -viewWillDisappear 方法中发布通知,该方法通过呈现 View Controller 接收。
最佳答案
如果你有
BOOL b = NO;
然后你在它之后打破程序并做
po b
你会得到
<nil>
做
p b
反而
po
代表 print object
,但 bool 不是对象,而是原始类型。这些应该用 p
打印。 -命令。nil
对象的地址为 0x0
, 这将评估为 0
或 NO
以及。
关于iOS:为什么没有设置 BOOL 属性?属性(property)值(value)为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25037547/