Brain Fade with NSView layout
Brain Fade with NSView layout
- Subject: Brain Fade with NSView layout
- From: Greg Hulands <email@hidden>
- Date: Sat, 28 Sep 2002 00:46:11 +1000
Hi,
I seem to be suffering from Friday night brain fade. I have been trying
for the last 4 hours to get this layout to be correct. I have a
Subclassed NSView that is an inspector view that autogenerates the view
depending on the object it is inspecting. The object returns an array
of dictionaries that provides the inspector view the information it
needs to generate the subviews. Depending on the type the attribute is
(NSString, NSColor, etc) it will create a "cell" as it were (not a
subclass of NSCell rather NSView) that allows the attribute to be
changed.
The method that sets all this up is as follows:
- (void)setupInspector
{
int i;
NSEnumerator *g = [[self subviews] objectEnumerator];
id curView;
while (curView = [g nextObject])
[curView removeFromSuperview];
if (![_inspectingObject
conformsToProtocol:@protocol(TADesignInspection)])
return;
NSRect size = NSMakeRect(NSMinX([self frame]), NSMinY([self
frame]), NSWidth([self frame]), [[_inspectingObject
inspectionProperties] count] * TAInspectorCellHeight);
[self setFrame:size];
int e = [[_inspectingObject inspectionProperties] count];
NSDictionary *cur;
float w = NSWidth([self bounds]);
for (i = 0; i < e; i++)
{
cur = [[_inspectingObject inspectionProperties]
objectAtIndex:i];
NSString *classStr = [cur
objectForKey:TADesignInspectionClassKey];
NSRect r = NSMakeRect(0, (i * TAInspectorCellHeight), w,
TAInspectorCellHeight);
TAInspectorCell *cell;
if ([classStr isEqualToString:TADesignClassInt])
{
cell = [[TAInspectorIntCell alloc] initWithFrame:r];
}
else if ([classStr isEqualToString:TADesignClassFloat])
{
cell = [[TAInspectorFloatCell alloc] initWithFrame:r];
}
....
....
else
{
NSLog(@"Unkown inspector type: %@", classStr);
return;
}
[cell setAttribute:[cur
objectForKey:TADesignInspectionNameKey]];
[cell setTarget:_inspectingObject];
[cell setGetSelector:NSSelectorFromString([cur
objectForKey:TADesignInspectionGetSelectorKey])];
[cell setSetSelector:NSSelectorFromString([cur
objectForKey:TADesignInspectionSetSelectorKey])];
[self addSubview:cell];
[cell release];
}
}
The problem is that it is only displaying the first "cell" and no
others. I have checked the frames of all the subviews which are
correct, yet it does not display them. When setting the frame for the
cell to be (0,0, w, TAInspectorCellHeight) it will display all the
cells over the top of each other (which one would expect), yet when it
is set to be what it is in the code above, it does not display them.
It is so frustrating as it must be such a simple thing yet the Friday
night brain fade has set in and is clouding my judgement. Damn you
Johnny Walker and Jim Beam!
Any help is greatly appreciated,
Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.