IBは、オブジェクトに割り当てることができるクラスの名前を表示します。カスタムクラスが1つしかない場合(「myCustomClass」など)、ドロップダウンメニューにそのクラスのみが表示されます。
1つのクラスのみを使用する場合、問題の最善の解決策は、描画コードを2つの別々の関数に配置し、各ビューにIBOutletを割り当ててから、コントローラークラスから関数を呼び出すことだと思います。
//Add this to your interface
NSNumber *myColor;
//Add/Edit the following functions
- (void)drawRect:(NSRect)aRect
{
//Some code...
if ([myColor intValue]) [self drawGreen];
else [self drawRed];
//Some code...
}
- (void)drawGreen
{
NSRect bounds = [self bounds];
[[NSColor greenColor] set];
[NSBezierPath fillRect:bounds];
}
- (void)drawRed
{
NSRect bounds = [self bounds];
[[NSColor redColor] set];
[NSBezierPath fillRect:bounds];
}
- (void)drawRedOrGreen:(int)aColor
{
myColor = [NSNumber numberWithInt:aColor];
}
コントローラのインターフェイスに次の2行を追加する必要があります
IBOutlet myCustomClass *customView1;
IBOutlet myCustomClass *customView2;
また、各ビューの色を設定する必要があります。これにより、初めてロードするときに設定されます。
- (void)awakeFromNib
{
[customView1 drawRedOrGreen:1]; //Green
[customView2 drawRedOrGreen:0]; //Red
}
このようにして、各ビューの色が異なります。
別の解決策は、独自の描画コードを持つ2つの別個のカスタムクラス(「myCustomClass1」と「myCustomClass2」など)を作成することです。