我正在发送带有枚举的通知:
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationTitle object:nil userInfo:@{[NSNumber numberWithInt:option2]:kNotificationName}];
并收到它:
- (void)myAction:(NSNotification *)notification {
MyState myState = (MyState)[[[notification userInfo] objectForKey:kNotificationName] integerValue];
问题是 myState 的值错误。当我打印通知时,我得到:
Printing description of notification:
NSConcreteNotification 0x123456 {name = notificationTitle; userInfo = {2 = notificationName;}}
但是 myState == option0。
为什么会这样?
编辑:
typedef enum myStates {
option0,
option1,
option2,
option3
} MyState;