Redraw view on dropdown change?

Discussion in 'Mac Programming' started by hjalmarsn, Mar 10, 2011.

  1. hjalmarsn macrumors newbie

    Joined:
    Mar 10, 2011
    #1
    Hello!
    Say that I have this view called "MyView" located in my main window.
    And I have these three dropdowns called "Shadow", "Color" and "Border" also located in my main window.

    Whenever I change one of these dropdowns I want the view to update with the selected property!
    How do I do this? I'm currently just able to draw a square in the view :(

    Please help me out on this one!

    Thank you!
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
  3. Oligarch macrumors newbie

    Joined:
    Nov 10, 2008
    #3
    (1) Create a new Objective-C class, e.g., AppController.
    (2) Give it an IBOutlet for the view. Give it an IBAction instance method, e.g., handleDropdown.
    (3) Instanciate your class in the nib (or xib) file, by dragging an object from the palette into the document (the little window with file's owner and first responder, not the window containing your view) and setting its type to AppController (in the inspector).
    (4) Have the outlet point to your view, by right-clicking on AppController and dragging to the view.
    (5) Set your new instance of AppController as the target of the dropdown, by right-clicking on the dropdown and dragging to AppController.
    (6) In your handleDropdown method, query the dropdown (= sender) for its state and change the view as desired, finishing with [view setNeedsUpdate:YES]. You might also put an NSLog() to see if the method gets called.
    (7) Build and run.
    And by all means, get yourself a good book on Cocoa programming.
     

Share This Page