テキストフィールドのオートコンプリートテキストフィールド機能を実行していますが、パフォーマンス時間が遅いため、キーパッドの任意の文字を押すと、最初に文字がズームされ、しばらくするとテキストフィールドに表示されます。オートコンプリート機能のリストはサービスのURLから取得されます。必要なのは、キーパッドで文字を入力するとすぐに、数秒以内に表示される必要があることです。サービスでチェックインされているため、表示されるまでに時間がかかることがわかりました。 urlとそのリスト。しかし、少なくとも私が今よりもいくらか速くそれを得ることができれば、それは勇気があるでしょう。
これは私が取り組んでいるコードです。
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(textField==CompanyName)
{
autocompleteTableView.hidden = NO;
NSString *substring = [NSString stringWithString:textField.text];
substring = [substring stringByReplacingCharactersInRange:range withString:string];
[self searchAutocompleteEntriesWithSubstring:substring];
return YES;
if([CompanyName.text length]==0)
{
autocompleteTableView.hidden = YES;
}
}
}
- (void)searchAutocompleteEntriesWithSubstring:(NSString *)substring {
NSString *urlString= [NSString stringWithFormat:@"http://221.190.132.116/services/AutoCompService.svc/GetEmpNames/?p=%@",substring];
NSURL *jsonUrl =[NSURL URLWithString:urlString];
NSURLRequest *request = [NSMutableURLRequest requestWithURL:jsonUrl];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
parser = [[NSXMLParser alloc] initWithData:data];
currentHtmlElement=@"5";
[parser setDelegate:self];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
[parser release];
if([arr4 count]!=0)
{
self.autocompleteUrls = [[NSMutableArray alloc] init];
if(autocompleteTableView)
[autocompleteTableView removeFromSuperview];
autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 110, 195, [arr4 count]*30) style:UITableViewStyleGrouped];
autocompleteTableView.delegate = self;
autocompleteTableView.dataSource = self;
autocompleteTableView.scrollEnabled = YES;
autocompleteTableView.backgroundColor = [UIColor lightTextColor];
autocompleteTableView.rowHeight=28;
autocompleteTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:autocompleteTableView];
[autocompleteUrls removeAllObjects];
for(int i=0;i<[arr4 count];i++)
{
NSString *curString = [[arr4 objectAtIndex:i] valueForKey:@"Name"];
[autocompleteUrls addObject:curString];
}
}
[autocompleteTableView reloadData];
}];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
CompanyName.text = selectedCell.textLabel.text;
autocompleteTableView.hidden=YES;
}
}
この機能を交互に実行するにはどうすればよいですか?