1

-(BOOL) textFieldShouldClear:(UITextField *)textFieldUITextFieldのクリアボタンがタップされたときに呼び出そうとしています。私はすでにデリゲートを設定しており、UITextField の他のデリゲートのメソッドは、これを除いて正しく呼び出されています。クリアボタンは、nib ファイルで「常に表示」に設定されています。

編集

参考までに、テキストフィールドのテキストが変更されたときにFPPopoverを表示しています。ポップオーバーを表示せずにクリアボタンをタップすると、クリアボタンが正常に機能します。しかし、ポップオーバーが表示されているときにタップしようとすると、delegate メソッドが呼び出されません。

コードスニペット

-(BOOL) textFieldShouldClear:(UITextField *)textField
{
    return YES;
}

- (IBAction)didChangeScripText:(id)sender {

    NSString *text = isPortrait ? symbolTextField.text : landsymbolTextfield.text;

    if(scripList.count == 0)
    {
        if([Logs sharedManager].scripData.count > 0)
            [self extractScrips];
        else
            return;
    }

    //        SAFE_ARC_RELEASE(popover);
//        popover=nil;

        //the controller we want to present as a popover
        if(controller == nil)
            controller = [[scripComboViewController alloc] initWithStyle:UITableViewStylePlain];

        if(controller.scripListFiltered.count > 0)
            [controller.scripListFiltered removeAllObjects];

        controller.delegate = self;
        if(popover == nil){
            popover = [[FPPopoverController alloc] initWithViewController:controller];
            popover.tint = FPPopoverDefaultTint;
        }

    controller.scripListFiltered = [NSMutableArray arrayWithArray:[scripList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",text]]];
    NSLog(@"array is: %@",controller.scripListFiltered);

    if(controller.scripListFiltered.count == 0)
    {
        [popover dismissPopoverAnimated:YES];
        return;
    }
        //decide contentsize and arrow dir based on tableview height

        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            popover.contentSize = CGSizeMake(300, 500);
        }
        else {
            popover.contentSize = CGSizeMake(200, 200);
        }

        //sender is the uitextfield
    float height = isPortrait ? portTable.frame.size.height : landTable.frame.size.height;
    if(height > 0)
        popover.arrowDirection = FPPopoverArrowDirectionDown;
    else
        popover.arrowDirection = FPPopoverArrowDirectionUp;

    if(![popover isModalInPopover])
        [popover presentPopoverFromView:sender];

    [controller reloadTable];

}

何がうまくいかないのですか?誰か教えてください。ありがとう。

4

2 に答える 2

0

実際の問題はFPPopoverによるものです。ビューの外でタッチ イベントを受け取ると、それ自体を終了し、その時点で外部コントロールとの対話はできません。したがって、クリアボタンをタップすると、ポップアップを閉じるために使用され、クリアボタンを使用できるようになります。それで全部です。

于 2013-03-29T04:52:52.610 に答える
-2

clearButtonModeのプロパティを使用しますUITextField。メソッドを使用する必要はありませんtextFieldShouldClear

textFiled.clearButtonMode = UITextFieldViewModeAlways;
于 2013-03-28T06:43:13.257 に答える