Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Four Little Problems

Four Little Problems

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

CocoaHeadsNYC

March 14, 2013
Tweet

More Decks by CocoaHeadsNYC

Other Decks in Programming

Transcript

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

    doRadioAction: multiRadioViewDidMakeSelection: Your action code target
  2. 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
  3. 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.
  4. 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.)
  5. 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;
  6. 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.
  7. Problem Focus rings where and when I want them. Standard

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

    Wrap views in custom superview. AKFocusView table view web view
  9. 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.
  10. Problem Control over key view loop. • NSBrowser not included

    by default. • Views in drawers not included. • Sometimes trapped in toolbar.
  11. 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;
  12. 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.