【发布时间】:2012-12-15 21:30:41
【问题描述】:
如标题中所述,我拥有UITextField 的属性。我将此UITextField 添加到UIView。
如果我有一个强指针,UITextField 就会出现,
如果我有一个弱指针,UITextField 不会出现。
当我有一个弱指针时出了什么问题?我对UIButton 做了同样的事情,然后它实际上出现了(带有强指针和弱指针)。
这里有一些代码:
CreateCategoryView.h
@interface CreateCategoryView : UIView
@property (weak, nonatomic) UITextField *nameTextField;
@end
CreateCategoryView.m
@implementation CreateCategoryView
- (id)initWithFrame:(CGRect)frame andParent {
self = [super initWithFrame:frame];
if (self) {
self.nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(5, 30, 310, 25)];
self.nameTextField.borderStyle = UITextBorderStyleRoundedRect;
self.nameTextField.textColor = [UIColor blackColor];
self.nameTextField.backgroundColor = [UIColor whiteColor];
[self addSubview:self.nameTextField];
}
return self;
}
@end
【问题讨论】:
-
你能贴一些代码sn-ps吗?因为这里有几件事可能会出错。您需要将标签添加到视图中,以便视图获得所有权。也不会显示没有文字的标签...
-
我将编辑我的问题。一秒
-
顺便说一句:我没有提到这一点,但我正在以编程方式创建 UITextField,而不是使用 Interface Builder。
-
您确定此代码有效吗?像 - (id)initWithFrame:(CGRect)frame andParent 这样的方法签名无法编译
标签: objective-c ios automatic-ref-counting