1

大きな問題に直面しています。内部をtextfieldタップするとアイテムのリストを表示するオートコンプリート機能を実行しています。tableView(オートコンプリートtableView)にアイテムを表示します。私はUIbutton以下を持っていますtextfield。オートコンプリート テキスト フィールドから項目を選択してボタンをクリックすると、応答しません。どうしてか分かりません。

私はそれを前に持ってきdidendeditingましたが、役に立ちませんでした. (testScroll)にdidSelectrow追加しましUIbuttonScrollView

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
           Name.text = selectedCell.textLabel.text;
           [Name resignFirstResponder];
           [testScroll bringSubviewToFront:btnSearch];
           autocompleteTableView.hidden=true;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
 if(textField==CompanyName)
    {

        [testScroll bringSubviewToFront:btnSearch];

}

}

どこが間違っているのですか?

編集:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {



    if(textField==Name)
    {

        autocompleteTableView.hidden = NO;

        NSString *substring = [NSString stringWithString:textField.text];
        substring = [substring stringByReplacingCharactersInRange:range withString:string];
        [self searchAutocompleteEntriesWithSubstring:substring];
        return YES;
        if([Name.text length]==0)
        {
            autocompleteTableView.hidden = YES;

        }
    }



}


- (void)connectionDidFinishLoading:(NSURLConnection *)connection

{

        parser = [[NSXMLParser alloc] initWithData:receivedData];
        [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]autorelease];
            viewForautoCompleteTableView = [[UIView alloc]initWithFrame:CGRectMake(220, 370, 295, 230)];



            if(autocompleteTableView)
                [autocompleteTableView removeFromSuperview];

            autocompleteTableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,295,150) style:UITableViewStyleGrouped];
            autocompleteTableView.delegate = self;
            autocompleteTableView.dataSource = self;
            autocompleteTableView.scrollEnabled = YES;
            autocompleteTableView.backgroundColor = [UIColor lightTextColor];
            autocompleteTableView.rowHeight=28;

            autocompleteTableView.backgroundView = nil;
            autocompleteTableView.backgroundColor = [UIColor whiteColor];


            autocompleteTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
            [autocompleteTableView setSeparatorColor:[UIColor orangeColor]];
            [viewForautoCompleteTableView setFrame:CGRectMake(220,370 ,295,autocompleteTableView.frame.size.height)];


            [viewForautoCompleteTableView addSubview:autocompleteTableView];
            [self.view addSubview:viewForautoCompleteTableView];

            [autocompleteUrls removeAllObjects];
            for(int i=0;i<[arr4 count];i++)
            {
             NSString *curString = [NSString stringWithFormat:@"%@ %@",[[arr4 objectAtIndex:i] valueForKey:@"Name"],[[arr4 objectAtIndex:i]valueForKey:@"LastName"]];

                [autocompleteUrls addObject:curString];

            }




        }
        [autocompleteTableView reloadData];


}
4

1 に答える 1

2

私は同じ問題を経験し、以下のコードの助けを借りて修正しました。

以下の 2 つの関数を次のように編集します。

in .h:

 int isValueSelected;

.m:

viewDidLoad: isValueSelected =0;

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

        if (isValueSelected == 1)
        {
            autocompleteTableView.hidden = YES;
            isValueSelected = 0;
        }else{
            NSString *substring = [NSString stringWithString:textField.text];
            substring = [substring stringByReplacingCharactersInRange:range withString:string];
            [self searchAutocompleteEntriesWithSubstring:substring];
            if((substring.length ==0) || ([substring characterAtIndex:0] == 10) || (autocompleteUrls.count == 0)){
                autocompleteTableView.hidden = YES;
            }else{
                autocompleteTableView.hidden = NO;
            }


        }

        return YES;
    }


    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

        UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
        urlField.text = selectedCell.textLabel.text;
        isValueSelected = 1;
        autocompleteTableView.hidden = YES;

    }
于 2013-02-28T06:35:13.887 に答える