Saturday, February 25, 2012

TextField in iPhone and How Keypad Go

This is my third tutorial for iPhone UI controls and today we will learn..

how to create a simple Text Field.
when i was started to work on iPhone programming, i got one strange thing that after entering the text in Text field the keypad will not go back and i got stuck.

so i have also write
How to Make the keyboard go away after entering Text?

my development environment is
iOS 5.0 on Mac OS X Lion with Xcode 4.2

Getting Started

Open up Xcode and create a new project with the iOS\Application\Single View Application template. 



 For the Product Name enter "TextField", for the Device Family choose iPhone and go next..

open header file "TextFieldViewController.h" and modify it like this..

now come to implementation file, open "TextFieldViewController.m" add two methods body at the end of file (remember we have already declared these method in header file)

now modify "viewDidUnload" method and release the ui controls
finally your "TextFieldViewController.m" file will look like this..

okay!! enough code now lets play with UI so just open "TextFieldViewController.xib" file
now drag TextField, Label and Button on View this way..
our phone no Text-Field should have number keypad so change like this
we are almost done! we have written code and drawn UI controls on view.. now we need to connect these so do this
1. connect Text-Field, Label and Button through File owner
  (i) Text-Field
 (ii) Label and do same for Button also

2. connect keyPadGo and showData method through  file owner
 (i) keyPadGo
 select "Did End On Exit" event
 (ii) showData
 select "Touch Up Inside" event

That's it!! now go for build and Run the project output will be like this..
click on Button to show data..
cheers!!
I'd love to hear your thoughts!!