NSTabViewItem identifier is NSNumber in one context, NSString in another
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 trea开发者_如何转开发t 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?
intValue is a method of NSString as well as NSNumber. The identifiers were strings all along.
精彩评论