title: iOS reload UITableView using UISegmentedControl
body: <p>Hi I'm trying to reload my table view based off of two different arrays. Which array should be loaded is determined by a segment control in the navigation bar. Currently it only will load the first array and nothing happens when the segment control is pressed. Below is my code any help as to why this isn't working is greatly appreciated. I've also checked that my IBAction segmenter is connected in the nib.</p>
  
  <p><strong>MessageViewController.h</strong></p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  
  @interface MessageViewController : UIViewController&lt;UITableViewDelegate&gt; {
      IBOutlet UISegmentedControl *segmentControl;
      IBOutlet UINavigationBar *navBar;
      IBOutlet UITableView *tableView;
  }
  
  @property (retain, nonatomic) IBOutlet UISegmentedControl *segmentControl;
  @property (retain, nonatomic) IBOutlet UITableView *tableView;
  @property (nonatomic, retain) NSMutableArray *inbox;
  @property (nonatomic, retain) NSMutableArray *sent;
  
  @end
  </code></pre>
  
  <p><strong>MessageViewController.m</strong></p>
  
  <pre><code>#import "MessageViewController.h"
  
  @interface MessageViewController () &lt;UITableViewDelegate&gt;
  
  @end
  
  @implementation MessageViewController
  @synthesize segmentControl;
  @synthesize inbox;
  @synthesize sent;
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          self.tabBarItem.title = NSLocalizedString(@"Messages", @"Messages");
          self.tabBarItem.image = [UIImage imageNamed:@"mail_2_icon&amp;32"];
      }
      return self;
  }
  
  - (void)viewDidLoad {
      [super viewDidLoad];
      self.tableView.delegate = self;
      self.inbox = [NSMutableArray arrayWithObjects:@"testing", @"test", @"another", nil];
      self.sent = [NSMutableArray arrayWithObjects:@"test", @"another", @"testing", nil];
  }
  
  - (void)didReceiveMemoryWarning {
      [super didReceiveMemoryWarning];
  }
  
  #pragma mark Table view methods
  
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 1;
  }
  
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
      if(segmentControl.selectedSegmentIndex == 0){
          return [inbox count];
      }else if(segmentControl.selectedSegmentIndex == 1){
          return [sent count];
      }else{
          return [inbox count];
      }
  }
  
  - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *CellIdentifier = @"Cell";
      UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
      }
      if(segmentControl.selectedSegmentIndex == 0){
          NSString *cellValue = [inbox objectAtIndex:indexPath.row];
          cell.textLabel.text = cellValue;
      }else if(segmentControl.selectedSegmentIndex == 1){
          NSString *cellValue = [sent objectAtIndex:indexPath.row];
          cell.textLabel.text = cellValue;
      }else{
          NSString *cellValue = [inbox objectAtIndex:indexPath.row];
          cell.textLabel.text = cellValue;
      }
      return cell;
  }
  
  -(IBAction)segmenter{
      [tableView reloadData];
  }
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  
  }
  
  - (void)dealloc {
      [inbox release];
      [sent release];
      [segmentControl release];
      [segmentControl release];
      [super dealloc];
  }
  
  - (void)viewDidUnload {
      [self setSegmentControl:nil];
      [segmentControl release];
      segmentControl = nil;
      [super viewDidUnload];
  }
  
  @end
  </code></pre>