I want a popup menu in my table view's corner view...
12/07/03 19:07
How ?
We will describe here one way of doing it. It is not the only one but once you understand it, you can easely imagine others ways.
In IB, create a custom view and put a NSPopupButton in it. Resize it so that it fits the size of the corner view of your table. Set its style to Shadowless Square with Arrow pointing: to the Right. The view here is only needed because you can't create an NSPopupButton outside of a view context.
If the popup menu has a fixed number of items, you can associated actions for each of its menu item. If your popup will behave dynamically, you need to create an outlet in your window controller class and connect it to the NSPopupButton, to be able to reference it from your code and to set each menu item action dynamically (by calling [myMenuItem setAction:@selector(menuItemAction:)] and [myMenuItem setTarget:myTargetForPopupMenuAction]).
You may also need an IBOutlet connected to the popup, if you need to enable/disable each menu item with more complex decision pattern than just the target implmementing the selector…
You also need an IBOutlet connected to the table view you want to set the corner view.
In the awakefromNib method of your window controller class, set the corner view of the table to be the NSPopupButton.
[ibTableView setCornerView:ibPopupButton] ;
That's it. From here you can imagine how to set the corner view to something else, to use a popup with another icon, etc.
In IB, create a custom view and put a NSPopupButton in it. Resize it so that it fits the size of the corner view of your table. Set its style to Shadowless Square with Arrow pointing: to the Right. The view here is only needed because you can't create an NSPopupButton outside of a view context.
If the popup menu has a fixed number of items, you can associated actions for each of its menu item. If your popup will behave dynamically, you need to create an outlet in your window controller class and connect it to the NSPopupButton, to be able to reference it from your code and to set each menu item action dynamically (by calling [myMenuItem setAction:@selector(menuItemAction:)] and [myMenuItem setTarget:myTargetForPopupMenuAction]).
You may also need an IBOutlet connected to the popup, if you need to enable/disable each menu item with more complex decision pattern than just the target implmementing the selector…
You also need an IBOutlet connected to the table view you want to set the corner view.
In the awakefromNib method of your window controller class, set the corner view of the table to be the NSPopupButton.
[ibTableView setCornerView:ibPopupButton] ;
That's it. From here you can imagine how to set the corner view to something else, to use a popup with another icon, etc.