即时通讯创建一个自定义的UITextField,但没有设置布尔?即时通讯客观C布尔没有设置
MyCustomTextField.h
#import <UIKit/UIKit.h>
@interface OMTextField : UIControl <UITextFieldDelegate>
{
UITextField *_theTextField;
BOOL _hasBackGroundImage;
}
@property (nonatomic, retain)UITextField *theTextField;
@property (nonatomic) BOOL hasBackGroundImage;
@end
MyCustomTextField.m
#import "OMTextField.h"
@implementation OMTextField
@synthesize theTextField = _theTextField;
@synthesize hasBackGroundImage = _hasBackGroundImage;
- (void)dealloc
{
[_theTextField release];
[super dealloc];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.theTextField = [[[UITextField alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]autorelease];
//self.theTextField.borderStyle = UITextBorderStyleLine;
self.theTextField.text = @"textField";
self.theTextField.delegate = self;
if (self.hasBackGroundImage) {
NSLog(@"lo tienes");
}
if (!self.hasBackGroundImage) {
NSLog(@"nana tienes");
}
[self addSubview:self.theTextField];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
,并在我的MainVC电话:
MyCustomTextField *textField = [[[MyCustomTextField alloc]initWithFrame:CGRectMake(400, 160, 150, 40)]autorelease];
textField.hasBackGroundImage = YES;
textField.backgroundColor = [UIColor grayColor];
textField.theTextField.borderStyle = UITextBorderStyleLine;
[self.view addSubview:textField];
因此它显示精细, 但正如你看到的IM设置textField.hasBackGroundImage = YES;
但是当执行时,我看到BOOL = NO?的消息。
nana tienes
那么,我缺少什么?,为什么这不被评估为YES?
谢谢!
好的答案约翰! – 2012-04-19 01:14:34