Re: Custom View in Toolbar
Re: Custom View in Toolbar
- Subject: Re: Custom View in Toolbar
- From: David Blanton <email@hidden>
- Date: Mon, 8 Mar 2010 11:58:20 -0700
Ok. Let me back up and repeat myself. I sure would like to solve this
problem.
Using IB I have added a Custom View from the Views & Cells Layout
Views to the Allowed Toolbar Items palette. To this view I have added
two Square Buttons from the Views & Cells Buttons selection. I then
dragged this view to the toolbar. Here is a picture: http://highrolls.net/Picture
1.png
When I build and run the view is not visible. So I read about
validating tool bar items:
View item validation
Validation for view items is not automatic because a view item can be
of unknown complexity. To implement validation for a view item, you
must subclass NSToolbarItem and override validate (because
NSToolbarItemÂ’s implementation of validate does nothing for view
items). In your override method, do the validation specific to the
behavior of the view item and then enable or disable whatever you want
in the contents of the view accordingly. If the view is an NSControl
you can call setEnabled:, which will in turn call setEnabled: on the
control.
In the absence of a custom menu form representation, NSToolbar by
default disables a view itemÂ’s overflow menu item.
I have sub classed as suggested:
@interface View : NSToolbarItem {
@public
}
@end
@implementation View
- (void)validate {
[self setEnabled:YES];
}
@end
and set this class to be the class of the enclosing tool bar item: http://highrolls.net/Picture
2.png
The buttons do not display.
I then added outlets for the buttons and tried to enable them (yes, I
realize that I if they were disabled I would see them in a disabled
state) but I am grasping at straws now. Doing this caused
EXEC_BAD_ACCESS the second time validate was called.
@interface View : NSToolbarItem {
@public
IBOutlet NSButton* m_button1;
IBOutlet NSButton* m_button2;
}
@end
@implementation View
- (void)validate {
[self setEnabled:YES];
[m_button1 setEnabled:YES];
[m_button2 setEnabled:YES];
}
@end
I am not sure how much more specific I can be.
Thanks.
-db
On Mar 8, 2010, at 10:21 AM, Kyle Sluder wrote:
On Mon, Mar 8, 2010 at 8:56 AM, David Blanton
<email@hidden> wrote:
Apparently you do as the custom view containing two buttons placed
in the
tool bar is not displayed.
There is no reason to believe that the solution to your problem is to
manually provoke -display. That's not how drawing works in AppKit. You
have made an erroneous leap of logic.
The docs for -validate indicate that -setEnabled should be called
if the
custom view is a control and that NStoolbarItem has no idea on how to
validate a custom view containing 'complex' controls. Did that,
don't work.
So you assume the solution is to manually draw the control? No, the
solution is to figure out why your code isn't working. Perhaps it has
something to do with the glaring memory management bug you have
written that manifests itself as an EXC_BAD_ACCESS exception.
But since you have posted no code, and have made no indication that
you have attempted to find the problem, nobody can offer more specific
advice.
So, it is not the workman it is the tool. Proven by how long it
took Apple
to include toolbar support in IB and the fact that there is not one
answer
or example anywhere on how to do what is supposed to be trivial.
Ergo, I
stand by may statement that a trivial task in MFC is consuming lots
of time
to do in Cocoa. Does that not point to either poor tool design or
poor
documentation?
No, it points to someone who is being obstinate and refusing to learn.
You can't blame the Toyota drivers for sudden acceleration when
Toyota
recalled 'the tool' to fix the problem. Analogous situation here.
Your lack of understanding and refusal to engage in basic
troubleshooting procedure is in no way analogous to a design flaw in a
formally specified realtime system.
So I ask again, how does one display a custom view containing
controls in a
toolbar?
I ask you again, what have you tried?
--Kyle Sluder
_______________________________________________
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