textFieldShouldBeginEditing未被调用 [英] textFieldShouldBeginEditing not being called

查看:224
本文介绍了textFieldShouldBeginEditing未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 textFieldShouldBeginEditing 来禁用键盘显示自定义 UITextField 。我正在实现所有 UITextFieldDelegate 方法。但是,由于某种原因, textFieldShouldBeginEditing 实际上永远不会被调用。

I am trying to use textFieldShouldBeginEditing to disable the keyboard from showing up for a custom UITextField. I'm implementing all the UITextFieldDelegate methods. However, for some reason, textFieldShouldBeginEditing actually never gets called.

以下委托方法总是被调用:

The following delegate methods ALWAYS get called:

– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:

视图的结构如下方式:

UIViewController ,其中包含一个scrollview。根据视图的状态,此ScrollView将包含 UIView ,其中包含自定义 UITextFields 的列表。

UIViewController which holds a scrollview. Depending on the state of the view, this ScrollView will contain a UIView with a list of custom UITextFields.

我在这台设备上运行iOS 4.3.5(8L1)。

I'm running iOS 4.3.5 (8L1) on this device.

有什么想法吗?

编辑;添加了一些代码片段:

Edit; added some code snippets:

UIViewController 具有以下界面

@interface AViewController: UIViewController<UITextFieldDelegate>

加载UIViewController后,我使用

Once the UIViewController loads, I connect all UITextFields to the view using

aSubView.aTextField.delegate = self;

(简化)委托实现

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
}

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

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

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

自定义 UITextField 代码

简化的实施文件 -

Simplified implementation file --

#import "PVEntryTextField.h"
#import "EntryViewController.h"

@implementation PVEntryTextField
@synthesize isPasswordField, state, singleTap;

- (id)initWithCoder:(NSCoder *)inCoder
{
    if (self = [super initWithCoder:inCoder])
    {
         self.font = [UIFont fontWithName:@"Helvetica-Bold" size:19];
         self.textColor = [UIColor colorWithRed:51.0/255.0 
                                         green:51.0/255.0 
                                          blue:51.0/255.0 
                                         alpha:1.0];
         self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    }

    return self;
}

- (CGRect)textRectForBounds:(CGRect)bounds
{
    return CGRectMake(bounds.origin.x + 16, bounds.origin.y,
                      bounds.size.width - 16*2 - 10, bounds.size.height);
}

- (CGRect) editingRectForBounds:(CGRect)bounds
{
    return [self textRectForBounds:bounds];
}

- (BOOL) canBecomeFirstResponder
{
    return YES;
}

- (void) updateState:(int) newState
{
     state = newState;
 }

- (void)dealloc
{
    [super dealloc];
}

 @end


推荐答案

是否可以通过 canBecomeFirstResponder 方法的默认实现来调用 textFieldShouldBeginEditing

Is it posible that textFieldShouldBeginEditing is called by the default implementation of the method canBecomeFirstResponder?

尝试通过 [super canBecomeFirstResponder] 实施该方法,或者只是删除它。

Try implementing the method by [super canBecomeFirstResponder] or just removing it.

这篇关于textFieldShouldBeginEditing未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆