IPhone UITextField does not show edit carriage or clear placeholder text when clicked

I have a window in the iPhone application that displays modally to allow the user to enter their settings for the web service on “first start”.

Auxiliary text is set in the text fields, and when you click on them, a keyboard appears that allows you to enter text.

Unfortunately, the text fields do not clear the auxiliary text, show the editing frame or show the input text (as in the screenshot below).

The wonderful issue ...

Any suggestions?

The window is displayed with [self presentModalViewController:<controller_name> animated:YES]; , which may or may not be the cause of this problem - when I launch the user interface through the interface builder test application, the text fields respond as usual.

Clear when editing begins been set for both fields.

Thanks in advance!

Edited: additional information After the information that Bart Gottschalk provided, I thought I should add some more information. Firstly, this is a navigation based application.

Secondly, the test application recommended by Bart worked fine, so it displays a modal window and a view from the equation.

Thirdly, I was presenting a modal view when -(void)viewWillAppear... the delegate method -(void)viewWillAppear... which may well be the wrong place ... however, I'm not 100% sure if I should represent the modal inside view didFinishLaunchingWithOptions application delegate ...

(this happens on the simulator and iPhone 3.1.3)

+6
iphone uitextfield
source share
3 answers

Well, I just figured it out, but to be honest, without Bart's persistence and huge help, it would take a lot more time and be a lot more unpleasant.

Turns out the problem was that I used Window instead of the view in the XIB file. That is why when displaying a modal view in the navigation controller, it will not display correctly (i.e. only a white screen) and why UITextField will not work properly when displaying a view from the RootViewController .

So, for recap - modal views should have a UIView , not a UIWindow in the XIB / NIB file.

Thanks for helping Bart!

+1
source share

In the Builder interface, have you checked the "Clear When Editing Begins" checkbox? When checking, the text box should clear any value after using the taps for editing, which is the behavior that I think you are looking for.

You can also set the same property programmatically using cleararsOnBeginEditing, if convenient in your code.

I assume that you did this and it does not behave as you expect. Just check it out as a first step to help you debug.

Also, does this happen in both the Simulator and the test device?

Bart

Edited below ...

That seems weird. Drop everything except the basics of presenting a modal view at application startup and see what happens.

I recreated the most basic application (which I know) to test the view of the modal view controller on startup and to verify that editing the fields works fine. What happens to you when you do the same / similar in a new project?

That's what I'm doing:
1) Create a new application based on the view in Xcode called "ModalViewTest"

2) Create a new UIViewController with xib called ModalViewController

3) In ModalViewController.h add a method

 -(IBAction)closeModalView; 

4) In ModalViewController.m add an implementation of the method as

 -(IBAction)closeModalView { [self dismissModalViewControllerAnimated:YES]; } 

5) In ModalViewController.xib, create two text fields and set the placeholder text for each in abcd1234 and make sure that the "Clear when editing" checkbox is selected.

6) In the ModalViewController.xib add the “Close” button and set “Touch Inward” to launch the “closeModalView”

7) In application deletion (ModalViewTestAppDelegate) add the following import

 #import "ModalViewController.h" 

8) In the applicationate application (ModalViewTestAppDelegate) applicationDidFinishLaunching, add the following after the line containing [window makeKeyAndVisible];

 ModalViewController *modalViewController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil]; [viewController presentModalViewController:modalViewController animated:YES]; 

9) Save all

10) Create and run this new application

Is editing text fields as expected? If so, what is the difference between the way you build and present your modalView? If not, then we will need to dig further to determine what is happening in your environment.

Second edit below ...

When creating a navigation-based application, I did the following to present a modal view when the application starts. Does this work for you both in the test application and in your real application?

 - (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after app launch [window addSubview:[navigationController view]]; [window makeKeyAndVisible]; ModalViewController *modalViewController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil]; [navigationController presentModalViewController:modalViewController animated:YES]; } 
+3
source share

I have the same problem, but only on iOS7. I solved this by changing the color of the textField to blue in the storyboard

0
source share

All Articles