I have a uipicker and i want to change what the array after switching a uisegementedcontrol. After a I switch, the list doesn't updated after I selected it, only after I turn it do the elements change and it will crashed at the bottom after it switches.

Does anybody know have to fix this. I have attached my code


#import <UIKit/UIKit.h>

@interface greekfinderViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>{
IBOutlet UIPickerView *doublePicker;
NSArray *greeklist;
NSArray *fraternityArray;
NSArray *sororityArray;
IBOutlet UISegmentedControl *fratsoro;

@property (nonatomic, retain) IBOutlet UISegmentedControl *fratsoro;
@property (nonatomic,retain) UIPickerView *doublePicker;
@property (nonatomic,retain) NSArray *greeklist;
@property (nonatomic,retain) NSArray *fraternityArray;
@property (nonatomic,retain) NSArray *sororityArray;

- (IBAction) setPicker: (id) sender;



#import "greekfinderViewController.h"

@implementation greekfinderViewController

@synthesize doublePicker;
@synthesize fratsoro;
@synthesize greeklist;
@synthesize sororityArray;
@synthesize fraternityArray;

// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibNameNSString *)nibNameOrNil bundleNSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
return self;

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
[super loadView];

-(void) frats

fraternityArray = [[NSArray alloc] initWithObjects:
@"Alpha Chi Rho",
@"Alpha Delta Gamma",
@"Alpha Delta Phi",
@"Alpha Epsilon Pi",
@"Alpha Gamma Rho",
@"Alpha Gamma Sigma",
@"Alpha Kappa Lambda",
@"Alpha Phi Alpha",
@"Alpha Phi Delta",
@"Alpha Sigma Phi",
@"Alpha Tau Omega",
@"Beta Chi Theta",
@"Beta Theta Pi",
@"Chi Phi",
@"Chi Psi",
@"Delta Chi",
@"Delta Epsilon Psi",
@"Delta Kappa Epsilon",
@"Delta Lambda Phi",
@"Delta Phi",
@"Delta Psi",
@"Delta Sigma Phi",
@"Delta Tau Delta",
@"Delta Upsilon",
@"Iota Nu Delta",
@"Iota Phi Theta",
@"Kappa Alpha Order",
@"Kappa Alpha Psi",
@"Kappa Alpha Society",
@"Kappa Delta Phi",
@"Kappa Delta Rho",
@"Kappa Sigma",
@"Lambda Chi Alpha",
@"Lambda Phi Epsilon",
@"Lambda Sigma Upsilon",
@"Lambda Theta Phi",
@"Omega Psi Phi",
@"Phi Alpha Epsilon",
@"Phi Beta Kappa",
@"Phi Beta Sigma",
@"Phi Delta Epsilon",
@"Phi Delta Psi",
@"Phi Delta Theta",
@"Phi Gamma Delta",
@"Phi Iota Alpha",
@"Phi Kappa Psi",
@"Phi Kappa Sigma",
@"Phi Kappa Tau",
@"Phi Kappa Theta",
@"Phi Mu Delta",
@"Phi Sigma Alpha",
@"Phi Sigma Kappa",
@"Phi Sigma Phi",
@"Pi Kappa Alpha",
@"Pi Kappa Phi",
@"Pi Lambda Phi",
@"Psi Upsilon",
@"Sigma Alpha Epsilon",
@"Sigma Alpha Mu",
@"Sigma Beta Rho",
@"Sigma Chi",
@"Sigma Lambda Beta ",
@"Sigma Nu",
@"Sigma Phi Delta",
@"Sigma Phi Epsilon",
@"Sigma Phi Society",
@"Sigma Pi",
@"Sigma Tau Gamma",
@"Tau Delta Phi",
@"Tau Epsilon Phi",
@"Tau Kappa Epsilon",
@"Theta Chi",
@"Theta Delta Chi ",
@"Theta Tau",
@"Theta Xi",
@"Zeta Beta Tau-",
@"Zeta Psi",


- (void) sorts{
sororityArray = [[NSArray alloc] initWithObjects:
@"Alpha Chi Omega",
@"Alpha Delta Pi",
@"Alpha Gamma Delta",
@"Alpha Epsilon Phi",
@"Alpha Omicron Pi",
@"Alpha Omicron Pi",
@"Alpha Phi",
@"Alpha Sigma Alpha",
@"Alpha Sigma Tau",
@"Alpha Xi Delta",
@"Gamma Phi Beta",
@"Delta Delta Delta",
@"Delta Gamma",
@"Delta Zeta",
@"Delta PHi Epsilon",
@"Zeta Tau Alpha",
@"Theata Phi Alpha",
@"Kappa Alpha Teta",
@"Kappa Delta",
@"Kappa Kappa Gamma",
@"Pi Beta Phi",
@"Sigma Delta Tau",
@"Sigma Kappa",
@"Sigma Sigma Sigma",
@"Phi Mu",
@"Phi Sigma Sigma",
@"Chi Omega",

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

[super viewDidLoad];
fratsoro.tintColor = [UIColor blueColor];
fratsoro.selectedSegmentIndex = 0;
[self frats];
self.greeklist =fraternityArray;
[fraternityArray release];


-(IBAction)setPicker id) sender{
switch (fratsoro.selectedSegmentIndex) {
case 0:
[self frats];
self.greeklist = fraternityArray;
case 1:
[self sorts];
self.greeklist = sororityArray;


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;

- (void)dealloc {
[doublePicker release];
[greeklist release];
[sororityArray release];
[fraternityArray release];
[super dealloc];
-(NSInteger)numberOfComponentsInPickerViewUIPickerView *)pickerView
return 1;

-(NSInteger)pickerViewUIPickerView *)pickerView
switch (fratsoro.selectedSegmentIndex) {
case 0:
return[fraternityArray count];
case 1:
return[sororityArray count];
return[fraternityArray count];
-(NSString *)pickerViewUIPickerView *)pickerView
switch (fratsoro.selectedSegmentIndex) {
case 0:
return[self.greeklist objectAtIndex:row];
case 1:
return[self.greeklist objectAtIndex:row];
return[self.greeklist objectAtIndex:row];