NSArrayController for polymorphic class
I have the following (stripped down) class interfaces:
@interface ScriptEvent : NSObject {
...
}
@interface SingleLine : ScriptE开发者_C百科vent {
NSString *line;
}
@interface MultiLine : ScriptEvent {
NSArray *lines;
}
Another parent class holds an NSArray
containing a list of ScriptEvent
s (which will either be SingleLine
or MultiLine
).
In my XIB I have an NSArrayController
bound to this list of ScriptEvent
s and I want to set up a master/detail arrangement. So I have an NSTableView
linking to this NSArrayController
and I want to show a different detail panel depending on whether the selected member of the NSArrayController
is a SingleLine
or a MultiLine
.
Is this possible?
Check if the selected member is a SingleLine or a MultiLine with:
if([objectToCheck isKindOfClass:[SingleLine class]]){
//Do some staff
}else if([objectToCheck isKindOfClass:[MultiLine class]]){
//
}else{
//
}
精彩评论