NSTabViewItem 标识符在一个上下文中是 NSNumber,在另一个上下文中是 NSString
我有四个 tabViewItems,在 IB 中分配了标识符 1、2、3 和 4,然后设置为常量,即:
#define kTabViewSubject 1
当测试选择哪个 tabViewItem 时,它会将标识符视为 NSNumbers,如下所示:
if ([self.drawerTabView selectedTabViewItem] identifier] intValue]]] == kTabViewSubject])
// do something
但是当选择时一个 tabViewItem,如果我将相同的标识符视为 NSNumber,就像这样......
[self.drawerTabView selectTabViewItemWithIdentifier:[NSNumber numberWithInt:kTabViewSubject]];
该标识符被评估为一个巨大的类似地址的数字,并且我得到一个“超出范围”异常。
有效的方法是将标识符视为 NSString,如下所示:
#define kTabViewSubjectX @"1"
// --
[self.drawerTabView selectTabViewItemWithIdentifier:kTabViewSubjectX];
我理解 NSTabViewItem 的标识符属性被设置为通用“id”。但为什么分类不一致呢?
I have four tabViewItems, with identifiers 1, 2, 3, and 4 assigned in IB, and then set up as constants, i.e.:
#define kTabViewSubject 1
When testing which tabViewItem is selected, it works to treat the identifiers as NSNumbers, like this:
if ([self.drawerTabView selectedTabViewItem] identifier] intValue]]] == kTabViewSubject])
// do something
But when selecting a tabViewItem, if I treat the same identifier as an NSNumber, like this…
[self.drawerTabView selectTabViewItemWithIdentifier:[NSNumber numberWithInt:kTabViewSubject]];
… the identifier is evaluated as a huge address-like number and I get a “beyond bounds” exception.
What works is to treat the identifier as an NSString, like this:
#define kTabViewSubjectX @"1"
// --
[self.drawerTabView selectTabViewItemWithIdentifier:kTabViewSubjectX];
I understand NSTabViewItem’s identifier property is set up as a generic “id.” But why is it inconsistently classed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
intValue 是 NSString 和 NSNumber 的方法。标识符一直都是字符串。
intValue is a method of NSString as well as NSNumber. The identifiers were strings all along.