Thursday, April 01, 2010

Create a new control - IPhone development

1. Create control in view using Interface Builder's Liberary. As shown below:

2. Create outlet in view controller code.
  • In the .h file, define the outlet for the control, example:
             IBOutlet UITextField *textField;   // add this to the @interface section
             @property (nonautomic,retain) UITextField *textField;   // add this outside of the @interface section

  • In the .m code, example:
             @synthesize textField;    //add this into the .m code after the @implement line

3. Link the control in Interface Builder view, to the defined Outlet variable. Example:
4. Now the control, can be used in the code.
                 textField.text = @"hello world";     // to assign hello world to the text field

5. As the textField variable is defined as retain in the .h file, it need to be manually released in the dealloc
- (void) dealloc  {
   [textField release];   // add this line to manually relase the textField variable
   [super dealloc];

No comments:

Post a Comment