iPad - UITextView和UITextField - 不显示文本

时间:2011-03-03 18:13:04

标签: ipad uitextfield uitextview

我在相同的视图中有一个UITextField和UITextView,但我在编辑时遇到了麻烦,特别是从一个到另一个时。

如果我点击UITextField,我就可以输入它。但是,如果我然后键入UITextView,那么它不会捕获我正在键入的内容。反之亦然。

为什么会出现这样的想法?

review = [[UITextView alloc] initWithFrame:CGRectMake(x+10, y + 40, 470-5, h - 15)];
review.keyboardType = UIKeyboardTypeAlphabet;
review.delegate = self;
review.font = [UIFont systemFontOfSize:16];
[scrollView addSubview:review];

titleField = [[UITextField alloc] initWithFrame:CGRectMake(x+10, y + 30, 472, 32)];
titleField.keyboardType = UIKeyboardTypeAlphabet;
titleField.clearButtonMode = UITextFieldViewModeWhileEditing;
titleField.delegate = self;
titleField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
titleField.font = [UIFont systemFontOfSize:14];
[scrollView addSubview:titleField];

这两个都是全局变量,它们的大小足够大。


所以我想出来了,但我不确定为什么会这样。

对象被释放,以至于我的指针不再准确了?

我的.h保持不变:

{ 
    UITextField *titleField;
    UITextView *review;
}
@property (nonatomic, retain) UITextField *titleField;
@property (nonatomic, retain) UITextView *review;

我改变了两个:

UITextField *titleField1 = [[UITextField alloc] initWithFrame:CGRectMake(x+10, y + 30, 472, 32)];
titleField1.keyboardType = UIKeyboardTypeAlphabet;
titleField1.clearButtonMode = UITextFieldViewModeWhileEditing;
titleField1.delegate = self;
titleField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
titleField1.font = [UIFont systemFontOfSize:14];
[scrollView addSubview:titleField1];

titleField = [titleField1 retain];

但即使在我发布titleField后,这是否会使对象悬空?

1 个答案:

答案 0 :(得分:0)

你不应该同时使用

{ 
UITextField *titleField;
UITextView *review;
}
@property (nonatomic, retain) UITextField *titleField;
@property (nonatomic, retain) UITextView *review;

使用:

@property (nonatomic, retain) IBOutlet UITextField *titleField;
@property (nonatomic, retain) IBOutlet UITextView *review;