I have an app i'm trying to port over to iOS 7. As there are no longer any textfields in iOS 7 UIAlertViews
. (See here ) I have to resort to using 2 UIViews
managed by 1 ViewController.
I didn't use nib files and just program the UI from code.
When the app is started, the second UIView
is stacked on top of the first one, it has a UITextField
that takes in a user input. This code works in iOS 7 but does not work on iOS 6 devices.
In an iOS 6 device, when I tap on the textfield in the 2nd UIView
, the keyboard appears. However when I enter something into the textfield, no characters appear. I even tried to NSLog
the characters entered by the keyboard and got NULL
which means no text is entered!
The code is as follows for the primary ViewController:
//View1 : UIView
View1 *aView1;
[aView1 initWithFrame:CGRectMake(20,40,280,200) title:promptMsg]
[self.view addSubview:aView1];
Inside the View1.m:
(id)initWithFrame:(CGRect) aRect title:(NSString*) promptStr{
self = [super initWithFrame:aRect];
UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(x,y,a,b)];
[self addSubview:userField];
Does any know what has changed in iOS 7 that 'allows' this behaviour? IS it a bug in iOS 7 or the SDK?
The problem is in your code i did not see any text you are setting, you are just allocating for example refer below:-
(id)initWithFrame:(CGRect) aRect title:(NSString*) promptStr{
self = [super initWithFrame:aRect];
UITextField *userField = [[UITextField alloc] initWithFrame:CGRectMake(x,y,a,b)];
userField.text=@"yourText"; // here setting the text
[self addSubview:userField];
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.