In this tutorial will learn how to use iPhone View Based Application and on that view will display text on label which is typed on text field of the view with the round react button. In View Based Application there is view which is already loaded on window so whatever you do on view will be your output or will be displayed.
In this tutorial will learn how to use iPhone View Based Application and on that view will display text on label which is typed on text field of the view with the round react button. In View Based Application there is view which is already loaded on window so whatever you do on view will be your output or will be displayed.iPhone View Based Application
In this tutorial will learn how to use View Based Application and on that view will display text on label which is typed on text field of the view with the round react button. In View Based Application there is view which is already loaded on window so whatever you do on view will be your output or will be displayed.
Final view will look like:
To Make View Based Application we have to do the following
Xcode->File->New Project->Application->View Application.
Then will ask you for project name give name and then you will see that you will have window and view in Interface Builder, view will be loaded on window automatically.
My project name is ViewBased and ViewController file will do our coding i.e. .h and .m file of ViewController.
In ViewBasedViewController.h will declare Text field and label, text field is used to enter data into and label is used to shoe or display text on view, Action to the button.
Add this in .h file:
IBOutlet UITextField *mtext; IBOutlet UILabel *mlabel; @property(nonatomic,retain) IBOutlet UITextField *mtext; @property(nonatomic,retain) IBOutlet UILabel *mlabel; - (IBAction) magic:(id) sender; |
And in .m file will write the method for that action, in that method will check the length of the text field if entered text is equal to zero then the message will be display as please enter something and if length of text field is not equal to zero then the message will be you Entered __________ and after that will release the variable created. And also synthesize the variable which is declared in .h file.
Add this in .m file:
-(IBAction) magic:(id) sender { NSString *text; if([mtext.text length] == 0) { text = @"Please enter Something"; } else { text = [[NSString alloc] initWithFormat:@"You Entered %@", mtext.text]; } mlabel.text = text; [text release]; } |
Make connection of Appropriate variable created by us in .h file and will connect it with the Text field, Label and the Action of button as shown,
And Finally Press Build And Go button