0

UITextView のカスタマイズされたオートコンプリートを実行したい...

例えば:

  If the user starts to type "Busines" I would like to suggest "Business1", "Business2", , so that the user can select any one of the 2 suggestions or choose to type a new one.

すべてのカスタム単語の提案は配列になります...

どうすればこれを達成できますか??

completionsForPartialWordRange:inString:language:が使用できるものです..どうすれば配列に値を渡すことができますか???

4

1 に答える 1

0

このコードを試すことができます。

  - (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring 
{
    [autocomplete_array removeAllObjects];
    for(int i=0;i<[your_main_array count];i++)
    {
         NSString *curString = [your_main_array objectAtIndex:i];
         curString = [curString lowercaseString];
         substring = [substring lowercaseString];

         if ([curString rangeOfString:substring].location == NSNotFound) 
         {} 
         else 
         { 
             [autocomplete_array addObject:curString] 
         }  
    }
    [autocompletedisplayTableView reloadData];
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text 
{
    if( textView == your_TextView)
    {
        [your_TextView resignFirstResponder];
        autocompletedisplayTableView.hidden = NO;

        NSString *substring = [NSString stringWithString:your_TextView.text];
        substring = [substring stringByReplacingCharactersInRange:range withString:string];
        [self searchAutocompleteEntriesWithSubstring:substring];
        return YES;
    }
}

your_main_array : Web サービスからロードする元の配列になります。autocomplete_array : 検索プロセスが終了した後に取得する配列になります。

ユーザーが検索するときは、 autocomplete_array をあなたに渡す必要がありますUITableView

于 2013-01-10T06:21:22.650 に答える