Re: Argument not getting passed to method
Re: Argument not getting passed to method
- Subject: Re: Argument not getting passed to method
- From: Ken Tozier <email@hidden>
- Date: Sun, 1 Jul 2007 20:02:06 -0400
The snipped parts didn't seem like they would make any difference re
the problem but here they are
// superview
- (NSRect) expandedFrame
{
NSRect oldFrame = [self frame];
NSLog(@"collapsibleView calling contentView sizeWithWidth: %f",
oldFrame.size.width);
NSSize conSize = [[contentView sizeWithWidth:
oldFrame.size.width] sizeValue];
contentHeight = (contentView == nil) ? contentHeight :
conSize.height ;
return NSMakeRect(oldFrame.origin.x, oldFrame.origin.y -
contentHeight, oldFrame.size.width, titleHeight + contentHeight);
}
// subview
- (NSValue *) sizeWithWidth:(float) inWidth
{
NSLog(@"Entered KMatrixView:sizeWithWidth: %f", inWidth);
float usableWidth = inWidth - 2 * margin,
cellsPerRow = floor((usableWidth + horizontalSpacing) /
cellWidthPlusSpacer),
rowCount = ceil([cells count] / cellsPerRow);
return [NSValue valueWithSize: NSMakeSize(inWidth, 2 * margin +
rowCount * cellSize.height + verticalSpacing * (rowCount - 1))];
}
I return an NSValue here rather than a plain old NSSize because the
compiler spit out a real error (not just a warning) when I define
"sizeWithWidth" like this
- (NSSize) sizeWithWidth:(float) inWidth
and call it like this:
NSSize conSize = [contentView sizeWithWidth: oldFrame.size.width];
Does that shed any light on the matter
On Jul 1, 2007, at 7:45 PM, Martin Redington wrote:
re preserving the generic method, you could use respondsToSelector()
to check if the object does implement the sizeWithWidth method before
invoking the method.
as far as your warning goes, you could cast the object to the
appropriate subclass, or declare the method in a protocol to eliminate
it. That is good practise (eliminating the warning).
As for your actual problem, I'd either step through the code in the
debugger or add more logging. In your expandedFrame method you snipped
out the interesting bits, but it sounds like some kind of trivial
error rather than anything deep.
On 7/2/07, Ken Tozier <email@hidden> wrote:
Hi
I'm pretty sure this is some sort of runtime thing I'm not familiar
with but I'm getting this bug where, directly before calling a
method, I NSLog the value of a float argument and it's OK, but upon
entering the method, another NSLog prints 0.0. The context of the
call is a custom view class querying a subview for it's width. The
subviews can be any number of different classes so the calling view
doesn't know at compile time that the method is real. Xcode spits out
the following error for the method on compiles:
"warning: no 'sizeWithWidth:' method found."
I was under the impression that even if these sorts of warnings pop
up, the runtime system does the necessary method lookup so these
warnings can be safely ignored. Is that not the case?
Here's the relevant code:
// superview method
- (NSRect) expandedFrame
{
NSRect oldFrame = [self frame];
// next line prints the correct value to the run log
NSLog(@"collapsibleView calling contentView sizeWithWidth:
%f",
oldFrame.size.width);
/* snip */
}
// subview method
- (NSValue *) sizeWithWidth:(float) inWidth
{
// next line prints "0.0" to the run log
NSLog(@"Entered KMatrixView:sizeWithWidth: %f", inWidth,);
/* snip */
}
Anyone see what I'm doing wrong here? Is there another way to
preserve the generic method call without resorting to the laborious
process of setting up an NSInvocation or "performSelector:withObject?
I'd like to avoid performSelector if possible as other parts of my
app use the "sizeWithWidth" method and I don't want to have to write
another one that handles NSNumbers if I don't have to.
Thanks for any help
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40mildmanneredindustries.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden