osx - NSTextField in NSTableCellView - end editing on loss of focus -


i have view view-based nstableview (which has cell view single text field) , buttons , textfields outside tableview. 1 of buttons adds object datasource tableview, , after inserting row tableview, makes editable.

if user enters text , pressed return key, receive - (bool)control:(nscontrol *)control textshouldendediting:(nstext *)fieldeditor delegate method fine, , can run validation , save value. delegate doesn't called if user selects of other buttons or textfields outside tableview.

what's best way detect loss-of-focus on textfield inside nstablecellview, can run of validation code on tableview entry?

if understand correctly want control:textshouldendediting: notification fire in following situation:

  1. you add new object array controller.
  2. the row in table representing object automatically selected.
  3. you programmatically select text field in relevant row editing.
  4. the user (i.e. without making edits in text field) gives focus control elsewhere in ui

one approach i've used in past working make insignificant programmatic change field editor associated text field, before text field becomes available user editing. snippet below shows how - step 2/step 3 in above scenario:

func tableviewselectiondidchange(notification: nsnotification) {     if justaddedtoarraycontroller == true {         // change of selection occurring because user has added new         // object array controller, , has been automatically selected          // in table view. need give focus text field in          // newly selected row...          // access cell         var cell = tableview.viewatcolumn(0,             row: arraycontroller.selectionindex,             makeifnecessary: true) nstablecellview          // make text field associated cell first responder (i.e.          // give focus)         window.makefirstresponder(cell.textfield!)          // access, 'nudge' field editor - make think it's         // been edited it'll fire 'should' messages if user          // doesn't add text field         var fe = tableview.window?.fieldeditor(true, forobject: cell.textfield!)         fe!.inserttext(cell.textfield!.stringvalue)     } } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -