iPhone 运营商
好的,我已经定义了我的 DSNavigationManager 类,它有一个名为 DSNavigationManagerStyle managerStyle
的属性:
typedef enum {
DSNavigationManagerStyleNone = 0,
DSNavigationManagerStyleDefaultNavigationBar = 1 << 0,
DSNavigationManagerStyleDefaultToolBar = 1 << 1,
DSNavigationManagerStyleDefault =
DSNavigationManagerStyleDefaultNavigationBar +
DSNavigationManagerStyleDefaultToolBar,
DSNavigationManagerStyleInteractiveNavigationBar = 1 << 2,
DSNavigationManagerStyleInteractiveToolBar = 1 << 3,
DSNavigationManagerStyleInteractiveWithDarkPanel = 1 << 4,
DSNavigationManagerStyleInteractiveWithBackButton = 1 << 5,
DSNavigationManagerStyleInteractiveWithTitleBar = 1 << 6,
DSNavigationManagerStyleInteractiveDefault =
DSNavigationManagerStyleInteractiveNavigationBar +
DSNavigationManagerStyleInteractiveToolBar +
DSNavigationManagerStyleInteractiveWithDarkPanel +
DSNavigationManagerStyleInteractiveWithBackButton +
DSNavigationManagerStyleInteractiveWithTitleBar,
} DSNavigationManagerStyle;
我刚刚学会了如何使用按位移位,但我不知道如何接收此信息。我想做一些类似的事情:
DSNavigationManagerStyle managerStyle = DSNavigationManagerStyleDefault;
if(managerStyle "Has The DefaultNavigationBar bit or the DefaultToolBarBit") {
// Implement
}
else {
if(managerStyle "Has the InteractiveNavigationBar bit") {
// Implement
}
if(managerStyle "Has the InteractiveToolBar bit") {
// Implement
}
//.... and so on so that technically the object can implement all
// styles, no styles, or any number of styles in between
}
Okay so I have defined my DSNavigationManager class and it has a property called DSNavigationManagerStyle managerStyle
:
typedef enum {
DSNavigationManagerStyleNone = 0,
DSNavigationManagerStyleDefaultNavigationBar = 1 << 0,
DSNavigationManagerStyleDefaultToolBar = 1 << 1,
DSNavigationManagerStyleDefault =
DSNavigationManagerStyleDefaultNavigationBar +
DSNavigationManagerStyleDefaultToolBar,
DSNavigationManagerStyleInteractiveNavigationBar = 1 << 2,
DSNavigationManagerStyleInteractiveToolBar = 1 << 3,
DSNavigationManagerStyleInteractiveWithDarkPanel = 1 << 4,
DSNavigationManagerStyleInteractiveWithBackButton = 1 << 5,
DSNavigationManagerStyleInteractiveWithTitleBar = 1 << 6,
DSNavigationManagerStyleInteractiveDefault =
DSNavigationManagerStyleInteractiveNavigationBar +
DSNavigationManagerStyleInteractiveToolBar +
DSNavigationManagerStyleInteractiveWithDarkPanel +
DSNavigationManagerStyleInteractiveWithBackButton +
DSNavigationManagerStyleInteractiveWithTitleBar,
} DSNavigationManagerStyle;
I just learned how to use bit-wise shifting but I don't know how to receive this information. I want to do something a little like:
DSNavigationManagerStyle managerStyle = DSNavigationManagerStyleDefault;
if(managerStyle "Has The DefaultNavigationBar bit or the DefaultToolBarBit") {
// Implement
}
else {
if(managerStyle "Has the InteractiveNavigationBar bit") {
// Implement
}
if(managerStyle "Has the InteractiveToolBar bit") {
// Implement
}
//.... and so on so that technically the object can implement all
// styles, no styles, or any number of styles in between
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要检查特定位是否存在,请使用按位与
&
(不要与逻辑与&&
混淆)。例如,如果您使用此值,它将被转换为布尔值,则任何非零值都被视为“true”,这使得这样的测试易于阅读:
但是此测试不适用于您的复合值 - 对于例如,如果设置了位字段的任何组成位,则使用
DSNavigationManagerStyleDefault
处理位字段将返回“true”。如果您确实想使用位域,请习惯所有按位运算符: http://developer.apple.com/tools/mpw-tools/commandref/appc_逻辑.html
To check for the presence of a particular bit, use the bitwise and,
&
(not to be confused with&&
, the logical and). For example,If you use this value where it will be cast to boolean, any non-zero value is considered "true," which makes tests like this easy to read:
But this test won't work well with your compound values - for example, anding a bitfield with
DSNavigationManagerStyleDefault
will return 'true' if any of its component bits are set.If you really want to use bitfields, accustom yourself to all the bitwise operators: http://developer.apple.com/tools/mpw-tools/commandref/appc_logical.html
&
是按位 AND 运算符。您应该阅读有关按位运算的维基百科文章。&
is the bitwise AND operator. You should read the Wikipedia article on Bitwise operation.