title: EXC_BAD_ACCESS when calling reloaddata from segment
body: <p>I have segment control with 3 segments initially it displays data in tableview. When i click on the other segment it gives me this exception. Really hard to figure out what is the problem. I can post the code if requested.</p>
  
  <pre><code>libobjc.A.dylib`objc_msgSend:
  0x192308c:  movl   8(%esp), %ecx
  0x1923090:  movl   4(%esp), %eax
  0x1923094:  testl  %eax, %eax
  0x1923096:  je     0x19230e8                 ; objc_msgSend + 92
  0x1923098:  movl   (%eax), %edx
  0x192309a:  pushl  %edi
  0x192309b:  movl   8(%edx), %edi     &lt;-------HERE 
  0x192309e:  pushl  %esi
  0x192309f:  movl   (%edi), %esi
  0x19230a1:  movl   %ecx, %edx
  0x19230a3:  shrl   $2, %edx
  0x19230a6:  andl   %esi, %edx
  0x19230a8:  movl   8(%edi,%edx,4), %eax
  0x19230ac:  testl  %eax, %eax
  0x19230ae:  je     0x19230b9                 ; objc_msgSend + 45
  0x19230b0:  cmpl   (%eax), %ecx
  0x19230b2:  je     0x19230d0                 ; objc_msgSend + 68
  0x19230b4:  addl   $1, %edx
  0x19230b7:  jmp    0x19230a6                 ; objc_msgSend + 26
  0x19230b9:  popl   %esi
  0x19230ba:  popl   %edi
  0x19230bb:  movl   4(%esp), %edx
  0x19230bf:  movl   (%edx), %eax
  </code></pre>
  
  <p>My Segment switch method. Its Segment 1 which is the one not working.</p>
  
  <pre><code>- (IBAction)segmentSwitch:(id)sender
  {
    NSInteger selectedSegment = [sender selectedSegmentIndex];
  
    if(selectedSegment == 0)
    {
  
      [tableview1 reloadData];
    }
    if(selectedSegment == 1)
    {
      NSLog(@"Above reloaddata");
      [tableview1 reloadData];
      NSLog(@"Below reloaddata");
    }
    if(selectedSegment == 2)
    {
      UIAlertView *save = [[[UIAlertView alloc]
                            initWithTitle:@"Alert!"
                            message:@"No Data Found"
                            delegate:self
                            cancelButtonTitle:@"Ok"
                            otherButtonTitles: nil] autorelease];
      [save show];
   }
  }
  </code></pre>
  
  <p>TableView Delegates</p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
  if(tableView == tableview1){
      NSInteger selectedSegment = segmentControl.selectedSegmentIndex;
      if(selectedSegment == 0)
          return arraycontacts.count;
      if(selectedSegment == 1)
      {
           return phPatch.count; 
      }
  
  
   }
   else
      return 0;
   }
  
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath    *)indexPath
  {
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
  
  if(cell==nil)
  {
      cell= [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]autorelease];
  
  }
  
  if(tableView == tableview1){
  
      NSInteger selectedSegment = segmentControl.selectedSegmentIndex;
  
      if(selectedSegment == 0){
          NSLog(@"In segment 0");
  
          cell.textLabel.text=[arraycontacts objectAtIndex:indexPath.row];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;
  
          UILabel *typeLabel = [[[UILabel alloc]init]autorelease];
          typeLabel.backgroundColor = [UIColor clearColor];
          typeLabel.text = [arraypatch objectAtIndex:indexPath.row];
          typeLabel.textAlignment = UITextAlignmentCenter;
          typeLabel.frame = CGRectMake(300,2.0f,150,50);
          [cell addSubview:typeLabel];
  
  
          UILabel *typeLabel1 = [[[UILabel alloc]init]autorelease];
          typeLabel1.backgroundColor = [UIColor clearColor];
          typeLabel1.text = [arrayclass objectAtIndex:indexPath.row];
          typeLabel1.textAlignment = UITextAlignmentCenter;
          typeLabel1.frame = CGRectMake(400,2.0f,150,50);
          [cell addSubview:typeLabel1];
  
  
          UILabel *typeLabel2 = [[[UILabel alloc]init]autorelease];
          typeLabel2.backgroundColor = [UIColor clearColor];
          typeLabel2.text = [arrayspeciality objectAtIndex:indexPath.row];
          typeLabel2.textAlignment = UITextAlignmentCenter;
          typeLabel2.frame = CGRectMake(500,2.0f,250,50);
          [cell addSubview:typeLabel2];
  
  
          UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(770,2.0f,250,50)] autorelease];
          UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
          btn.frame = CGRectMake(10,0, 150, 40);
          [btn setTitle:@"Precall" forState:UIControlStateNormal];
          [btn addTarget:self action:@selector(precallClicked:) forControlEvents:UIControlEventTouchUpInside];
          [headerView addSubview:btn];
          [cell addSubview:headerView];
  
          cell.tag = indexPath.row;
  
      }
  
     if(selectedSegment == 1){
  
         NSLog(@"In segment 1");
  
         cell.textLabel.text=[phPatch objectAtIndex:indexPath.row];
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
  
          UILabel *typeLabel = [[[UILabel alloc]init]autorelease];
          typeLabel.backgroundColor = [UIColor clearColor];
          typeLabel.text = [phName objectAtIndex:indexPath.row];
          typeLabel.textAlignment = UITextAlignmentCenter;
          typeLabel.frame = CGRectMake(300,2.0f,150,50);
          [cell addSubview:typeLabel];
  
          UILabel *typeLabel1 = [[[UILabel alloc]init]autorelease];
          typeLabel1.backgroundColor = [UIColor clearColor];
          typeLabel1.text = [phClass objectAtIndex:indexPath.row];
          typeLabel1.textAlignment = UITextAlignmentCenter;
          typeLabel1.frame = CGRectMake(400,2.0f,150,50);
          [cell addSubview:typeLabel1];
  
  
      }   
     }
     return cell;
    }
  </code></pre>
  
  <p>Thank You.</p>