0

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

 "**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;
}
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
Sonu
  • 937
  • 1
  • 10
  • 39

3 Answers3

0

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.

[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 
Praveen S
  • 10,355
  • 2
  • 43
  • 69
0

You are using a Class level method "+" to return a text field instance, change it to Instance Level Method "-". i.e:

-(UITextField*)tableLabelForText:(NSString *)txt frame:(CGRect)frm isEditable:(BOOL)isEditable 
Jamal Zafar
  • 2,179
  • 2
  • 27
  • 32
0

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. Instead use UIView

@interface ClassName : UIView  <UITextFieldDelegate>
Dushyant Singh
  • 721
  • 4
  • 13