cocoa - Autoselect, focus and highlight a new NSOutlineView row -
this lack of experience nsoutlineview
can't see way this. have nsoutlineview
(implemented excellent pxsourcelist) add button totally functional in aspect save/write/insert/delete rows correctly. not use nstreecontroller
, , don't use bindings. add entity using following code:
- (void)addentity:(nsnotification *)notification { // create core data representation, , add child parent node uabasenode *node = [[uamodelcontroller defaultmodelcontroller] createbasenode]; [sourcelist reloaddata]; (int = 0; < [sourcelist numberofrows]; i++) { if (node == [sourcelist itematrow:i]) { [sourcelist selectrowindexes:[nsindexset indexsetwithindex:i] byextendingselection:no]; [sourcelist editcolumn:0 row:i withevent:nil select:no]; break; } } }
when add button pressed, new row inserted this:
if click away, select row , press enter
edit it, looks this:
my question is: how can programmatically same state (focus, selected, highlighted) first time, make user experience better?
something works me:
- (void)addentity:(nsnotification *)notification { // create core data representation, , add child parent node uabasenode *node = [[uamodelcontroller defaultmodelcontroller] createbasenode]; [sourcelist notenumberofrowschanged]; nsinteger row = [sourcelist rowforitem:node]; [sourcelist scrollrowtovisible:row]; [sourcelist selectrowindexes:[nsindexset indexsetwithindex:row] byextendingselection:no]; [sourcelist editcolumn:0 row:row withevent:nil select:yes]; }
you can use rowforitem:
instead of repeatedly checking itematrow:
.
you want use [sourcelist scrollrowtovisible:...]
in case new row isn't visible , can use notenumberofrowschanged
instead of reloaddata
, unless data has changed.
the standard mac behavior select contents of newly created item, use select:yes
.
if doesn't help, there's else going on in code above snippet doesn't communicate...
in general, i'd suggest when learning new class read way through documentation page listing methods available (excepting deprecated methods), or @ least methods available task you're trying perform; you'll better idea of capabilities of class , less use inappropriate/inefficient/inelegant method.
Comments
Post a Comment