home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / Misc / HigherEducationMailbox.mbox / Archives_provide_val_.attach / May_91 / appkit.503 < prev    next >
Text File  |  1991-05-21  |  3KB  |  61 lines

  1. {\rtf0\ansi{\fonttbl\f2\fnil Times-Roman;\f1\fmodern Courier;}
  2. \paperw12540
  3. \paperh6580
  4. \margl120
  5. \margr120
  6. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f2\b0\i0\ul0\fs28 PopUpList PopUp IB attach button\
  7. \
  8. Q:  How do I create a PopUpList or pull-down list using interface builder?\
  9. \
  10. Q:  I've created a PopUpList and set its action, but it doesn't work.\
  11. \
  12. A:  In release 2.0, PopUpLists are easily created with Interface Builder.\
  13. \
  14. In release 1.0, you cannot directly create a PopUpList using Interface Builder.  Instead, you should place an ordinary button where you want the PopUpList to appear.  To give the button the appearance of a PopUpList, simply open Interface Builder's Inspector for the button's Attributes, click on the diamond under "Icon Position" so that it shows "Icon" rather than "Title" in the middle, and type "popup" in the "Icon:" field above (followed by a carriage return or a click on "OK").   Similarly, typing "pulldown" will give your button the appearance of a pull-down list.\
  15. \
  16. Next, you need to initialize it using code such as this.  Note that if you set a target/action for the button using Interface Builder, then the PopUpList won't pop up anymore.  Use the technique in the code here:\
  17. \
  18. - setButton:anObject\
  19. \{\
  20.   id aPopUp;\
  21. \
  22.   button = anObject;\
  23. \
  24.   aPopUp = [PopUpList new];\
  25.   [aPopUp addItem:"Red"];\
  26.   [aPopUp addItem:"Green"];\
  27.   [aPopUp addItem:"Blue"];\
  28.   /*\
  29.    * The itemList of a PopUpList is a matrix.  We get at the underlying\
  30.    * matrix and call selectCellAt on it to select something other than the\
  31.    * first element of the list.  This must be done before the call to\
  32.    * NXAttachPopUpList.\
  33.    */\
  34.   [[aPopUp itemList] selectCellAt:1:0];\
  35.   NXAttachPopUpList(button, aPopUp);\
  36. \
  37.   /*\
  38.    * NXAttachPopUpList sets the target of the button to aPopUp and sets the\
  39.    * action of the button to @selector(popUp:).  You CANNOT use Interface\
  40.    * Builder to set the target/action of the button (via control-drag) -- if\
  41.    * you do, then the button will no longer communicate with the PopUpList\
  42.    * properly.\
  43.    *\
  44.    * So you must set the target and action of the PopUpList, not the button,\
  45.    * as follows.\
  46.    */\
  47.   [aPopUp setTarget:self];\
  48.   [aPopUp setAction:@selector(doPopUpThing:)];\
  49.   return self;\
  50. \}\
  51. \
  52. \
  53. To create a pull-down list, send the PopUpList the message changeButtonTitle:NO.\
  54. \
  55. QA503\
  56.     \
  57. Valid for 1.0\
  58. Not valid for 2.0 (Interface Builder  provides all the functionality for PopUpList and PullDownList).\
  59. \
  60.  
  61.