![](/img/trans.png)
[英]-[UIView setContentSize:]: unrecognized selector sent to instance 0x16d3be60
[英][UIView setText:]: unrecognized selector sent to instance 0x89625d0
我試圖在視圖中添加自定義復選框...我在情節提要上繪制視圖,並借助名為UICheckbox的第三方代碼來訪問它。
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
在我的viewDidLoad
...
self.checkbox.text = @"Want to get the updates directly";
我像這樣執行動作
-(IBAction)testCheckbox:(id)sender {
NSLog(@"checkbox.checked = %@", (self.checkbox.checked) ? @"YES" : @"NO");
}
從情節提要的角度來看。...我排好出口,摸了摸各自的信息,並得到此錯誤。
請幫忙...
這很簡單,但是當我在代碼中更改插座類型時,我得到了完全相同的錯誤-看起來它仍連接在情節提要中,但事實並非如此。 我只需要將情節提要中的插座(例如,標簽)重新連接到代碼插座即可。 您不會考慮這一點,因為插座仍標記為已連接,但如果您進行了更改,則不會。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.