开发者

How Can I Get Rid Of This Warning?

开发者 https://www.devze.com 2023-02-28 14:38 出处:网络
I\'m getting a warning at line (theTextField.delegate = self;) that says \"Assigning to \'id from incompatible type Alert Prompt\"

I'm getting a warning at line (theTextField.delegate = self;) that says "Assigning to 'id from incompatible type Alert Prompt"

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelBu开发者_Python百科ttonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle
{

    if (self == [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil])
    {
        UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 
        [theTextField setBackgroundColor:[UIColor whiteColor]]; 
        [self addSubview:theTextField];
        self.textField = theTextField;
        [theTextField release];
        CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -25.0); 
        [self setTransform:translate];

        theTextField.backgroundColor = [UIColor clearColor];
        theTextField.borderStyle = UITextBorderStyleRoundedRect;
        theTextField.delegate = self;
    }
    return self;
}


About this property in the docs

@property(nonatomic, assign) id<UITextFieldDelegate> delegate

It means, your class must conform to UITextFieldDelegate protocol.
Declaration could look like this

@interface MyController : NSObject <UITextFieldDelegate> {


Try with below code and let me know if you still get the same warning.

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle okButtonTitle:(NSString *)okayButtonTitle
{

    if (self == [super initWithTitle:title message:message delegate:delegate cancelButtonTitle:cancelButtonTitle otherButtonTitles:okayButtonTitle, nil])
    {
        UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)]; 
        [theTextField setBackgroundColor:[UIColor whiteColor]]; 

        theTextField.backgroundColor = [UIColor clearColor];
        theTextField.borderStyle = UITextBorderStyleRoundedRect;
        theTextField.delegate = self;

        self.textField = theTextField;
        [theTextField release];
        [self addSubview:textField ];
        CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -25.0); 
        [self setTransform:translate];
    }
    return self;
}

Also check whether your class confirm with UITextFieldDelegate protocol.

0

精彩评论

暂无评论...
验证码 换一张
取 消