Define in the #ViewController.h file


@interface #ViewController_iPhone : UIViewController
{
    IBOutlet UISegmentedControl *mySegmentedControl;
}
- (IBAction)mySegmentedControlChanged:(id)sender;
In the #ViewController.m file

- (IBAction)mySegmentedControlChanged:(id)sender
{
}

Connect In Interface Builder
Right click Segmented Control, select ‘Value Changed’ and drag button onto ‘Files Owner’, select mySegmentedControlChanged
Right click ‘Files Owner’ and select the ‘mySegmentedControl’ outlet and drag onto the Segmented Control.

If your View could get unloaded you must release objects you’ve created (or you’ll have a memory leak) in #ViewController.m


//*************************************
//*************************************
//********** VIEW DID UNLOAD **********
//*************************************
//*************************************
- (void)viewDidUnload
{
    [super viewDidUnload];

    [mySegmentedControl release];
    mySegmentedControl = nil;
}

//*****************************
//*****************************
//********** DEALLOC **********
//*****************************
//*****************************
- (void)dealloc
{
    [mySegmentedControl release];

    [super dealloc];
}

Change the control like this


    mySegmentedControl.selectedSegmentIndex = 3;
If you want to call the function from other code

    [self mySegmentedControlChanged:nil];