首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITextfield应该清除:不被UITextfield调用

UITextfield应该清除:不被UITextfield调用
EN

Stack Overflow用户
提问于 2013-03-28 06:38:16
回答 1查看 3.8K关注 0票数 2

当UITextField的清除按钮被点击时,我试图调用-(BOOL) textFieldShouldClear:(UITextField *)textField。我已经设置了我的委托,UITextField的其他委托方法正在被正确调用,除了这个方法。在nib文件中,清除按钮设置为“始终可见”。

编辑

当textfield的文本被更改时,我正在显示FPPopover。如果我点击清除按钮,而不显示弹出,清除按钮工作良好。但是,如果在显示popover时尝试点击它,则不会调用委托方法。

代码片段

代码语言:javascript
复制
-(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];

}

出什么问题了?有人能告诉我。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-29 04:52:52

实际上,问题是由FPPopover造成的。当它接收到其视图之外的触摸事件时,它会拒绝自己,并且在那个时候不可能与外部控件进行交互。因此,如果点击清除按钮,它将用于关闭弹出,然后我可以使用清除按钮。仅此而已。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15675677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档