iPad - UITextView and UITextField - not showing text
I have a UITextField and UITextView in the same view but I'm having trou开发者_如何学JAVAble with them being editable, especially when going from one to the other.
If I tap in the UITextField, I'm able to type in it. But if I then type into the UITextView, then it doesn't capture what I'm typing. And the same happens visa-versa.
Any ideas why it is behaving like this?
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];
and
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];
Both of these are global variables and their sizes are large enough.
So I figured it out, but I'm not sure why it is this way.
The objects were being released such that my pointers weren't accurate anymore?
My .h stayed the same:
{
UITextField *titleField;
UITextView *review;
}
@property (nonatomic, retain) UITextField *titleField;
@property (nonatomic, retain) UITextView *review;
And I changed both to be like this:
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];
But doesn't this leave the object hanging even after I release titleField?
You should not use both
{
UITextField *titleField;
UITextView *review;
}
@property (nonatomic, retain) UITextField *titleField;
@property (nonatomic, retain) UITextView *review;
USE:
@property (nonatomic, retain) IBOutlet UITextField *titleField;
@property (nonatomic, retain) IBOutlet UITextView *review;
精彩评论