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;
}
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
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. Instead use UIView
@interface ClassName : UIView <UITextFieldDelegate>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.