multithreading - Cocoa: Delaying one method call until a subsequent call is processed -
i've found myself in following situation: i've got nstableview
subclass active cell. when click elsewhere on user interface, delegate method (i) fired, in turn fires (ii) (my own method) cocoa proceeds process click, resulting in final 2 calls. surprised , disappointed sequence, since had assumed mouse click first rather last event processed. causes me problem because ideal implementation of managestate
dependent on of processing in mousedown:
, of course when managestate
called mousedown:
has not yet been executed.
is way delay execution of managestate
until mousedown
has returned? example, in managestate
i'd stop! mouse down event might in events queue. wait until it's finished, resume. previous sentence implies, it's possible method triggered other mouse down. in situation, there's no need out mouse down event , processing can continue normal.
mouse click on nstextview while nstableview cell has focus... +-------------------------+--------------------------------------------------------+ |event |triggered because | +=========================+========================================================+ |controltextdidendediting:|the mouse click ends editing session | | |of active cell in table view | +-------------------------+--------------------------------------------------------+ |managestate |this method selector belongs notification| | |that fired within controltextdidendediting: | +-------------------------+--------------------------------------------------------+ |becomefirstresponder |i clicked on nstextview instance | +-------------------------+--------------------------------------------------------+ |mousedown: |finally, click started processed | +-------------------------+--------------------------------------------------------+
i figured 1 out myself. feared i'd have cobble threads-based solution, bit more docs-scouring turned nsevent
class method addlocalmonitorforeventsmatchingmask:handler
.
when app starts call method, define associated block, , 'tell' method events want out for. then, whenever 1 of these events detected, block runs. crucially ,this happens before of processing precipitated event set in motion. in block have opportunity stop event in tracks, or let processing continue, have access event . going question, means inserting additional row @ top of table. perfect since allows me act on event before of subsequent event executes.
[nsevent addlocalmonitorforeventsmatchingmask:nsleftmousedownmask handler:^nsevent *(nsevent *event) { // whenever event of type nsleftmousedownmask detected, code // run before other event processing // processing, then... return event; // or nil, if want block event }];
Comments
Post a Comment