简体   繁体   English

在uitextfield的委托中得到警告

[英]getting warning in uitextfield's delegate

I'm new in iphone development.now, I'm facing one warning in my project.while,setting the delegate of UITextfield in ios 6 I'm getting the warning that 我是iphone开发的新手。现在,我在我的项目中面临一个警告。同时,在ios 6中设置UITextfield的委托我得到了以下警告:

 "**incompatible pointer types sending 'class' to parameter of type '<uitextfielddelegate>'**"


+(UITextField*)tableLabelForText:(NSString *)txt frame:(CGRect)frm isEditable:(BOOL)isEditable 

{

    UITextField *txtField = [[UITextField alloc] initWithFrame:frm];
    [txtField setEnabled:isEditable];

    [txtField setText:txt];

    [txtField setTextColor:[UIColor blackColor]];
    [txtField setDelegate:self];

    return txtField;
}

You are trying to assign the delegate in a class method which has no idea of the initialised object. 您试图在不知道初始化对象的类方法中分配委托。 Hence the warning. 因此,警告。 What you need to do is setDelegate to the initialised object. 您需要将setDelegate设置为初始化的对象。

[txtField setDelegate:<MyObject>]; 

Or you can as one of the answers suggests change the class methods to instance method. 或者,您可以作为答案之一建议将类方法更改为实例方法。

-(UITextField*)tableLabelForText:(NSString *)txt frame:(CGRect)frm isEditable:(BOOL)isEditable 

You are using a Class level method " + " to return a text field instance, change it to Instance Level Method " - ". 您正在使用类级别的方法“ + ”来返回文本字段实例,将其更改为“实例级别的方法“ - ”。 ie: 即:

-(UITextField*)tableLabelForText:(NSString *)txt frame:(CGRect)frm isEditable:(BOOL)isEditable 

If I am not wrong , you are setting Delegate for an NSObject class , as NSObject class does not have any views , so UITextFieldDelegate does not confirms to the class. 如果我没看错,您正在为NSObject类设置Delegate,因为NSObject类没有任何视图,所以UITextFieldDelegate不会向该类确认。 Instead use UIView 而是使用UIView

@interface ClassName : UIView  <UITextFieldDelegate>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM