i have table enters in string (from table's cell label) wherever user has cursor - functions keyboard strings keys instead of individual characters.
i want able delete same string whatever textfield user in (e.g., safari address bar) if user clicks on same row twice or clicks different row after selecting first.
the code below inserts text upon first clicking row - how delete exact text when clicking row twice, or selecting different row?
note string inserted different sizes.
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { var string = buttontitles[indexpath.row] (textdocumentproxy as! uikeyinput).inserttext("\(string)") }
use variable keep track of row pressed last. when didselectrowatindexpath called, compare new row (from parameter) variable, , if same, delete word, , if different, delete word , add new word.
maybe code below. not sure if backspace technique work, it's try.
func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { let newtext = "\(buttontitles[indexpath.row])" let oldtext = "\(buttontitles[lastrow])" var stringtoadd = "" //only delete text if row has been selected if lastrow != -1 //-1 default value meaning there no last row { //delete old word in 0 ..< oldtext.length { stringtoadd += "\b" //add backspace characters remove old word } } //add new word if indexpath.row != lastrow { stringtoadd += rowtext } (textdocumentproxy as! uikeyinput).inserttext(stringtoadd) lastrow = indexpath.row }
Comments
Post a Comment