Satya P Dash
Satya P Dash

Reputation: 21

[UIView setText:]: unrecognized selector sent to instance 0x89625d0

I was trying to add a customized checkbox to my view...I draw a view on my storyboard and with the help of a third party code named UICheckbox I am accessing it.

UICheckbox.h

#import <UIKit/UIKit.h>

@interface UICheckbox : UIControl

-(void)setChecked:(BOOL)boolValue;
-(void)setDisabled:(BOOL)boolValue;
-(void)setText:(NSString *)stringValue;

@property(nonatomic, assign)BOOL checked;
@property(nonatomic, assign)BOOL disabled;
@property(nonatomic, strong)NSString *text;

@end

UICheckbox.m

#import "UICheckbox.h"

@interface UICheckbox (){
    BOOL loaded;
} 

@property(nonatomic, strong)UILabel *textLabel;

@end



@implementation UICheckbox
@synthesize checked = _checked;
@synthesize disabled = _disabled;
@synthesize text = _text;
@synthesize textLabel = _textLabel;

- (void)awakeFromNib {
    self.backgroundColor = [UIColor clearColor];
}

-(void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed:[NSString    stringWithFormat:@"uicheckbox_%@checked.png", (self.checked) ? @"" : @"un"]];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

    if(self.disabled) {
        self.userInteractionEnabled = FALSE;
        self.alpha = 0.7f;
    } else {
        self.userInteractionEnabled = TRUE;
        self.alpha = 1.0f;
    }

    if(self.text) {
        if(!loaded) {
            _textLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width +  5, 0, 1024, 30)];
            _textLabel.backgroundColor = [UIColor clearColor];
            [self addSubview:_textLabel];

            loaded = TRUE;
        }

        _textLabel.text = self.text;
     }
}

-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
    [self setChecked:!self.checked];
    return TRUE;
}

-(void)setChecked:(BOOL)boolValue {
    _checked = boolValue;
    [self setNeedsDisplay];
}

-(void)setDisabled:(BOOL)boolValue {
    _disabled = boolValue;
    [self setNeedsDisplay];
}

-(void)setText:(NSString *)stringValue {
    _text = stringValue;
    [self setNeedsDisplay];
}

@end

in my viewDidLoad ...

self.checkbox.text = @"Want to get the updates directly";

and I implemented the action as like this

-(IBAction)testCheckbox:(id)sender {
    NSLog(@"checkbox.checked = %@", (self.checkbox.checked) ? @"YES" : @"NO");
}

From the view of storyboard....I lined up the outlet and Touched up to the respective messages and getting this error..

Please help...

Upvotes: 1

Views: 3527

Answers (1)

Jolly
Jolly

Reputation: 283

This is pretty simple but I got that exact same error when I changed the outlet type in the code - it looked like it was still connected in the storyboard, but it was not. I just had to reconnect the outlet (for example, label) in the storyboard to the code outlet. You would not think to this because the outlet is still marked connected, but it is not if you had made a change.

Upvotes: 4

Related Questions