以下是一个前期的基本功能思路仅作为备忘(这段代码只是前期一个demo,只是针对字母编码的一个业务逻辑,只是一个大体的思路,后期的改良基本上推翻了前期所有的代码,但是前期的代码中的思想仍然得到保留),正式版已经完成,由于经过多次改良后代码过多这里就不放出来了,正式版的代码经过改良后打英文表示五笔编码,打其它字符或者数字时直接上屏,在输入编码后再选数字表示选择提示字上屏,与真实pc端输入法达到一样的效果。
- (void)tfWrite {
NSMutableString *tmp = [NSMutableStringstring];
NSString *strLow = [self.tf.textlowercaseString];
tmp = [[NSMutableString alloc] initWithFormat:strLow,nil];
unichar cc;
if (tmp.length >=1) {
cc = [tmp characterAtIndex:tmp.length-1];
}
NSLog(@"cc:%c",cc);
if ((cc >= '1' && cc <='5') || (cc >='a' && cc <='z') || cc ==' ') {
if (1 ==self.tf.text.length && cc >='1' && cc <= '5') {
self.tf.text =@"";
}
if (self.tf.text.length >=2 && (cc >='1' && cc <='5')) {
int indexTmp = [[NSNumbernumberWithUnsignedChar:cc]intValue]-'0';
NSLog(@"indexTmp:%d",indexTmp);
self.tf.text =@"";
if (self.wordTmp ==nil) {
self.wordLabel.text = [self.wordArray[indexTmp-1]copy];
}else{
self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[indexTmp-1]copy]];
}
self.wordTmp = [self.wordLabel.textcopy];
}
if (4 ==self.tf.text.length && (cc >='a' && cc <= 'z')) {
self.states =YES;
}
if (5 ==self.tf.text.length && (cc >='a' && cc <= 'z')) {
self.tf.text =@"";
if (self.wordArray.count >0) {
if (self.wordTmp ==nil) {
self.wordLabel.text = [self.wordArray[0]copy];
}else{
self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[0]copy]];
}
}
self.wordTmp = [self.wordLabel.textcopy];
}
if (cc == ' ') {
if (self.tf.text.length ==1) {
self.tf.text =@"";
return;
}
self.tf.text =@"";
if (self.wordTmp ==nil) {
self.wordLabel.text = [self.wordArray[0]copy];
}else{
self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[0]copy]];
}
self.wordTmp = [self.wordLabel.textcopy];
}
}else {
self.tf.text =@"";
}
if (0 !=self.wordArray.count &&0 !=self.keyArray.count) {
[self.wordArrayremoveAllObjects];
[self.keyArrayremoveAllObjects];
}
for (int i =0; i <self.allKey.count; i++) {
if ([self.allKey[i]hasPrefix:[self.tf.textlowercaseString]]) {
[self.wordArrayaddObject:self.allWord[i]];
[self.keyArrayaddObject:self.allKey[i]];
//暂时只提示5个
if (5 ==self.wordArray.count) {
break;
}
}
}
if (self.states) {
if (1 ==self.wordArray.count) {
self.tf.text =@"";
if (self.wordTmp ==nil) {
self.wordLabel.text = [self.wordArray[0]copy];
}else{
self.wordLabel.text = [self.wordTmpstringByAppendingString:[self.wordArray[0]copy]];
}
self.wordTmp = [self.wordLabel.textcopy];
self.states =NO;
}
}
[self.tableViewreloadData];
}