0

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?

Community
  • 1
  • 1
gigasai
  • 564
  • 4
  • 23
  • 1
    If you only need to have a text field in your alert view, why don't you just use `UIAlertViewStylePlainTextInput` as the view's `alertViewStyle` property (available since iOS 5) and `textFieldAtIndex:` to customize the text field? – omz Oct 29 '13 at 13:12
  • Hi, thanks, I know this but my old code extended the UIAlertView to have up to 3 textfields so I needed something like a view :) – gigasai Oct 29 '13 at 14:17

1 Answers1

0

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];
}
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
  • Hi, I did a userField.text = @"somerandomtext"; but i still can't type on my iOS 6 device. – gigasai Oct 29 '13 at 13:45
  • try this code and check UITextField *txtField = [[UITextField alloc] initWithFrame:CGRectMake(5.0f, 6.0f, 278.0f, 32.0f)]; [txtField setPlaceholder:@"My placeholder"]; [txtField setFont:[UIFont systemFontOfSize:15.0]]; [txtField setBorderStyle:UITextBorderStyleRoundedRect]; [txtField setAutocorrectionType:UITextAutocorrectionTypeNo]; [txtField setAutocapitalizationType:UITextAutocapitalizationTypeNone]; [txtField setKeyboardType:UIKeyboardTypeEmailAddress]; [txtField setReturnKeyType:UIReturnKeyDone]; [txtField setClearButtonMode:UITextFieldViewModeWhileEditing]; – Hussain Shabbir Oct 29 '13 at 13:49
  • unfortunately that didn't work either.. thanks. I can see the placeholder text, my cursor but when i type nothing goes into the text field. – gigasai Oct 29 '13 at 13:55