Four Little Problems

Four Little Problems

Andy Lee talks about four Cocoa programming obstacles he encountered, and how resolved them.

017d0f30a86ccc1b1e812548b9bd83fa?s=128

CocoaHeadsNYC

March 14, 2013
Tweet

Transcript

  1. Four Little Problems Andy Lee for CocoaHeadsNYC, 2013-03-14

  2. Better solutions?

  3. Problem Make 3 NSMatrix controls behave as one.

  4. Problem Make 3 NSMatrix controls behave as one.

  5. Solution Make 3 NSMatrix controls behave as one. AKMultiRadioView delegate

    target Custom superview, plus delegation.
  6. Solution Make 3 NSMatrix controls behave as one. AKMultiRadioView delegate

    doRadioAction: multiRadioViewDidMakeSelection: Your action code target
  7. API Make 3 NSMatrix controls behave as one. @interface AKMultiRadioView

    : NSView @protocol AKMultiRadioViewDelegate
  8. API Make 3 NSMatrix controls behave as one. @interface AKMultiRadioView

    : NSView - id <AKMultiRadioViewDelegate> delegate; - (NSInteger)selectedTag; - (BOOL)selectCellWithTag:(NSInteger)tag; - (IBAction)doRadioAction:(id)sender; @protocol AKMultiRadioViewDelegate - multiRadioViewDidMakeSelection: (AKMultiRadioView *)mrv
  9. How to use Make 3 NSMatrix controls behave as one.

    • Set the superview class in IB. • Drop in the NSMatrix instances. • Use unique cell tags. • Connect targets and delegate. • Put action code in the delegate method.
  10. Problem Set text color for disabled buttons. Apple’s colors The

    colors I want (Those triangles are actually characters.) (Yeah, I know the difference is subtle.)
  11. Solution Set text color for disabled buttons. @interface AKButtonCell :

    NSButtonCell // AppKit passes in an all-gray string. // Override to change the string color. // Then call super. - (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView;
  12. How to use Set text color for disabled buttons. •

    Select your button’s cell in IB. • Set its class to AKButtonCell. • Set custom colors if you want.
  13. Credit Set text color for disabled buttons. http://stackoverflow.com/questions/ 6370500/nsbutton-set-text-color-in- disabled-mode/10632311#10632311

  14. Problem Focus rings where and when I want them. Standard

    focus ring bleeds. WebViews have no focus ring. I don’t like standard look.
  15. Solution Focus rings where and when I want them. AKFocusView

    Wrap views in custom superview. AKFocusView table view web view
  16. How to use Focus rings where and when I want

    them. • Embed any view in an AKFocusView. • No code required. • Redraws automatically as needed. • Draws focus ring as solid border. • Suppresses normal AppKit focus ring.
  17. Problem Control over key view loop.

  18. Problem Control over key view loop. • NSBrowser not included

    by default. • Views in drawers not included. • Sometimes trapped in toolbar.
  19. Solution Control over key view loop. @interface AKWindow : NSWindow

    - (void)setTabChain:(NSArray *)views; - (BOOL)handlePossibleTabChainEvent:(NSEvent *)e; //In NSApplication subclass, override: - (void)sendEvent:(NSEvent *)anEvent;
  20. Solution Control over key view loop. • I currently hack

    toolbar buttons in. • Should go into a separate class. • Note that [self window] may be a drawer. • Note Full Keyboard Access.
  21. All code is on github: aglee/appkido

  22. Demo

  23. That’s all, thanks!