Re: NSMatrix, NSForm - addRow - why above and not below?
Re: NSMatrix, NSForm - addRow - why above and not below?
- Subject: Re: NSMatrix, NSForm - addRow - why above and not below?
- From: Grandinetti Philip <email@hidden>
- Date: Tue, 13 Mar 2012 14:26:56 -0400
Thanks Keary,
It all makes sense. Deceptive is the word "below" in the reference guide, which I usually interpret using the direction of gravity.
Philip
On Mar 13, 2012, at 1:49 PM, Keary Suska wrote:
> On Mar 13, 2012, at 8:55 AM, Grandinetti Philip wrote:
>
>> I'm running into a strange behavior with NSForm (and also NSMatrix).
>>
>> (1) Using interface builder (in Xcode 4.3.1) I place an NSForm in a window. I add a NSButton and wire it to an IBAction that sends addRow to the NSForm.
>>
>> - (IBAction) addRow:(id)sender
>> {
>> [form addRow];
>> [form sizeToCells];
>> }
>>
>> The problem is that the new row is added ABOVE the existing row, not below as it's supposed to. I thought this was a problem coming from somewhere else in my app, but I created a new project in Xcode and this happens even in the simplest app.
>>
>> I must be doing something stupid wrong, but I can't find it. Any suggestions would be appreciated.
>
>
> It is a bit deceptive, but the problem is not what you think. The row is in fact added at the bottom, but when the view is resized it is sized from the bottom left corner, instead of the top left, which is intuitive for humanity but not apparently for the founders of Cocoa.
>
> To get the behavior you expect you need to either flip the coordinate system of the enclosing view or move the view back as such:
>
> - (IBAction) addRow:(id)sender
> {
> NSRect originalFrame = [form frame];
> [form addRow];
> [form sizeToCells];
> NSRect newFrame = [form frame];
> CGFloat delta = newFrame.size.height - originalFrame.size.height;
> newFrame.origin.y -= delta;
> [form setFrame:newFrame];
> }
>
> Note that -sizeToCells does not cause the view to be redrawn, so you will get drawing artifacts. You may use -selectTextAtIndex: to set focus on the new form field, which will avoid the drawing issues (maybe a little more functional than just calling -setNeedsDisplay:).
>
> HTH,
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>
_______________________________________________
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