UITextField does not show the assigned string - iphone

In my project (my first one) I try to assign a text to a textfield created in the Interface Builder.
[date setText:#"2010"];
I also tried using
date.text = #"2010"
I have created the Outlet and don't get any error... the text just doesn't show up.
Just in case it matters...
I prevent the keyboard from showing up and display a calendar instead (works).
Any idea what could be wrong?
Could it be a problem that I'm using delegate methods on the textFields to prevent displaying the keyboard?

If you don't want to edit text using a keyboard, then what is the use of UITextField?
Instead of using UITextField you can use a UILabel (as a global variable) to show the text and use a custom UIButton without a title and use its action for showing the calendar view. You can change the text of the label whenever you want in that class like viewWillAppear or viewDidAppear.

Related

How to make a contact field entry like this on iOS?

I have an application in which when tapping a button it will show a view to the user to enter the contact number of the user, like in the image below. Can anybody help me achieve this? I need my users to chose their country within the flags and corresponding stdcodes needs to be there
What I see in the example: a UIImageView for the country flag, a UILabel for the country code and a UITextField with a placeholder for the phone number. You can set de value for placeholder in IB or programmatically.
You will have to create a custom view for that.
Steps to do it:
Derive a class from UIView.
Add UIImageView, UILabel and UITextField into it.
Layout it properly.
On button click, show this view with proper frames/bounds.
Create a view like whatever you have shown and initially make it hidden, when user click on the button make the view visible.
ON action event add this sub view into your view
In Xib file,click the label and see the right side properties,In that properties you will find the placeholder option.In that placeholder,type the text you want.That text will be appeared as a hint for the user when he taps it.Or otherwise,directly in your code where you declare the label,in that label code
label.placeholder=#"Enter Contact here";

how to get the cursor in UITextView without keyboard?

I am developing a program in which I have UITextView in that I need a cursor without the key board.In this cursor is show only with the keyboard if I hide the keyboard cursor will also get hide.How can I get the cursor without the key board ?
The cursor is displayed as long as you UITextView is being edited.
Thus, you can change its inputView view to some other view if you need to, and it will be displayed instead of the keyboard.
See http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIResponder_Class/Reference/Reference.html
With this method you can add your custom inputView, a UIPickerView for example, or as you say you want you can add a minimalist hidden UIView.
If you want to restrict UITextField content, you still need to implement UITextFieldDelegate, as the user can still paste content to your text field!

how to open new view on touch even for uitextfield

I am just woundering if it is possible and if so how I could go about loading a new
view when the user touches a uitextfield?
What I am trying to do is load a new view where the user will use a picker to populate the UItextField instead of typing the word.
any help would be greatly appreciated
What you need here is the inputView property of UITextField. If you set this for a text field, then instead of the usual keyboard, the inputView object will pop up. I had created this example for a related problem which uses a UIPickerView as an inputView to a UITextField object. You can check it to see if it helps.

UIPicker in inappsettingskit

Using inappsettingskit, I'm searching for a way to display an uipickerview (with custom values) when clicking on a textfield cell (instead of a keyboard).
Is there any way to do so ?
Thanks for your help :)
Read the setting in you application and for showing picker view instead of standard keyboard use UITextField inputView property.
myTextField.inputView = myPickerView;
From Apple Documentation for inputView .
If the value in this property is nil,
the text field displays the standard
system keyboard when it becomes first
responder. Assigning a custom view to
this property causes that view to be
presented instead.

How can I show a UIDatePicker instead of a keyboard when a user selects a UITextField?

I have a nice clean UI within a table view which has a few text fields for the user to fill out. One of the fields is for the user's birthday.
I'd like to have it so that when the user selects the birthday field, a view containing a UIDatePicker would come up as, just like the different keyboards do when selecting a text field.
Can this be done? I would have to prevent the text field from being the first responder (to avoid having the keyboard come up) and I would have to animate the view sliding up if no keyboard was showing before.
Would presenting the view modally be an option? If so how would I go about doing it? From the documentation it seems that modal views still take up the whole screen, I just want to use the lower 216 pixels (height of the keyboard and UIDatePicker).
Any one have any tips on how to go about doing this?
Old question but the correct way to do this these days would be to set the UITextField's inputView to a picker you created somewhere. Something like this:
UIPickerView *myPicker = [[UIPickerView alloc] init];
// set picker frame, options, etc...
// N.B. origin for the picker's frame should be 0,0
[myTextField setInputView:myPicker];
When you go to edit a UITextField, iOS really just displays whatever view is at textField.inputView which by default is the keyboard, you can make it anything you want as long as it's a subclass of UIView.
Regarding animation, take a look at DateCell sample application -
http://developer.apple.com/library/ios/#samplecode/DateCell/Introduction/Intro.html
And in any case, the proper way to do this is set UITextField's inputView to show the picker instead of the keyboard. That's what it's meant to do. More on that here:
How can I present a picker view just like the keyboard does?
Cheers,
Oded.
I would implement this by just animating a view containing the UIDatePicker, a Done, and Cancel button) up from the bottom of the screen. Using CoreAnimation, this should be pretty easy.
Why are you using a text field if you don't want to accept user input from a keyboard? Instead use a UILabel subclass (where you override the touchesBegan/Ended:withEvent: set of methods to show the UIDatePicker) or a UIButton (where your action is a method which slides up the UIDatePicker).