iphone - UITextView Autocomplete modification -
i'm using htautocompletetextfield fill in uitextfield
predefined list, should user start typing in entry exists. there couple of problems i've been having however. first seems stop when comma typed in (but not apostrophes). i've been looking around , i'm not sure why it's doing it. thought @ 1 point comma different comma, apostrophe issue had due importing list word document. however, wasn't case. second issue more of addition i'm not sure how implement. want autosuggest detect suggestions words in mid string, not beginning. instance typing in "string" suggest "this string". how auto suggest, have no idea how above things.
nsstring *prefixlastcomponent = [componentsstring.lastobject stringbytrimmingcharactersinset:space]; if (ignorecase) { stringtolookfor = [prefixlastcomponent lowercasestring]; } else { stringtolookfor = prefixlastcomponent; } (nsstring *stringfromreference in colorautocompletearray) { nsstring *stringtocompare; if (ignorecase) { stringtocompare = [stringfromreference lowercasestring]; } else { stringtocompare = stringfromreference; } if ([stringtocompare hasprefix:stringtolookfor]) { return [stringfromreference stringbyreplacingcharactersinrange:[stringtocompare rangeofstring:stringtolookfor] withstring:@""]; } }
if give me pointers on how done, i'd appreciate it.
regards,
mike
managed go solving both issues. 1 uses git repository, reason why commas don't work when using preset methods because of nsarray *componentsstring = [prefix componentsseparatedbystring:@","];
. remove comma it's nsarray *componentsstring = [prefix componentsseparatedbystring:@""];
, should work nicely. fix other problem detects start of words, changed methods little. here changes in htautocompletemanager.m
int = 0; (nsstring *stringfromreference in colorautocompletearray) { nsstring *stringtocompare; if (ignorecase) { stringtocompare = [stringfromreference lowercasestring]; } else { stringtocompare = stringfromreference; } if ([stringtocompare hasprefix:stringtolookfor]) { //nslog(@"removing string: %@ atindex: %d", [colorautocompletearray objectatindex:i], i); [colorautocompletearray removeobjectatindex:i]; [colorautocompletearray insertobject:stringfromreference atindex:0]; //nslog(@"adding string atindex 0: %@", stringfromreference); return [stringfromreference stringbyreplacingcharactersinrange:[stringtocompare rangeofstring:stringtolookfor] withstring:@""]; } else if ([stringtocompare hassuffix:stringtolookfor] && ([stringtolookfor length] >= 3)) { return [nsstring stringwithformat:@" %@", stringfromreference]; } else if (!([stringtocompare rangeofstring:stringtolookfor].location == nsnotfound) && ([stringtolookfor length] >= 3)) { return [nsstring stringwithformat:@" %@", stringfromreference]; } ++i; }
the reason reordering array because after 3rd character typed prioritise other 2 if statements because reached first if there generic term in multiple entries in array (like "street" in list of locations). know it's not necessary have "hassuffix" if statement, left in case wants use on it's own. lastly, added in space before stringfromreference
doesn't weird when there's suggestion straight after input text. when exit uitextfield
remove space (inside htautocompletetextfield.m - commitautocompletetext
):
nsstring *currenttext = self.text; if ([self.autocompletestring isequaltostring:@""] == no && self.autocompletedisabled == no) { if ([self.autocompletestring hasprefix:@" "]) { self.autocompletestring = [self.autocompletestring substringfromindex:1]; } self.text = [nsstring stringwithformat:@"%@", self.autocompletestring]; self.autocompletestring = @""; [self updateautocompletelabel]; } return ![currenttext isequaltostring:self.text];
hope makes sense who's in similar situation.
mike
Comments
Post a Comment