cocoa - NSTableView Delete Row by clearing text -
i want simple table 1 string column adds new line using return key. want delete row if user clears text on particular row too.
i've managed add new line return key method:
-(bool)control:(nscontrol*)control textview:(nstextview*)textview docommandbyselector:(sel)commandselector{ if (commandselector == @selector(insertnewline:)) { [self returnkey]; return yes; } else if(commandselector == @selector(moveup:)){ [self tablemoveup]; return yes; } else if(commandselector == @selector(movedown:)){ [self tablemovedown]; return yes; } else{ nslog(@"%@", nsstringfromselector(commandselector)); } return no;
}
the problem deleting row when user clears text on row , hits return key. method being called before actual changes on table saved data source. i've tried getting datacell on column this:
nstextfieldcell *cell = [self.tableview.tablecolumns[0] datacell]; nslog(@"%@",cell.stringvalue);
but stringvalue not accurate. ideas on how achieve ? thank you!
since table column's data cell reused each row (set value , "stamp" in place when drawing, lather, rinse, repeat), odd place put kind of code. "stringvalue not accurate" observation big clue - it'll set whatever value cell last used draw, can't , shouldn't determined.
why not have data source manage it? when -tableview:setobjectvalue:fortablecolumn:row: called, check if obj empty string / nil / whatever, remove row , reload. "empty cell" user action; table view handles , lets data source (a controller) know when user committed change.
if want have "delete/backspace deletes row" customize nstextfieldcell send "mytablerowwasdeleted" notification, data source can observe , take appropriate steps end editing , remove "empty" row, reload.
Comments
Post a Comment