当UITextField的清除按钮被点击时,我试图调用-(BOOL) textFieldShouldClear:(UITextField *)textField。我已经设置了我的委托,UITextField的其他委托方法正在被正确调用,除了这个方法。在nib文件中,清除按钮设置为“始终可见”。
编辑
当textfield的文本被更改时,我正在显示FPPopover。如果我点击清除按钮,而不显示弹出,清除按钮工作良好。但是,如果在显示popover时尝试点击它,则不会调用委托方法。
代码片段
-(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];
}出什么问题了?有人能告诉我。谢谢。
发布于 2013-03-29 04:52:52
实际上,问题是由FPPopover造成的。当它接收到其视图之外的触摸事件时,它会拒绝自己,并且在那个时候不可能与外部控件进行交互。因此,如果点击清除按钮,它将用于关闭弹出,然后我可以使用清除按钮。仅此而已。
https://stackoverflow.com/questions/15675677
复制相似问题