Search code examples
iphoneobjective-cxcodeipad

prepareForSegue Function not returning original switch results after search


After preforming a search on my tableview and selecting a row, The detailed view controller (MOVdetailViewController) only updates the name and not the information (address, website and other things). Which is located in the MDVC.lodgeNumber that I have setup as a switch. Im now thinking this is not possible due to the detailed information being stored in a switch. All feed back is greatly appreciated

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{
  if ([segue.identifier isEqualToString:@"lodgedetail"]) {
      MOVDetailViewController *destViewController = segue.destinationViewController;
      MOVDetailViewController * MDVC = [[MOVDetailViewController alloc] init];


      NSIndexPath * path = [self.tableView indexPathForSelectedRow];
      NSString * thelodge = [filteredList objectAtIndex:path.row];

      MDVC = [segue destinationViewController];
      MDVC.lodgeNumber = path.row;
      MDVC.lodgeName = thelodge;



      NSIndexPath *indexPath = nil;

      if ([self.searchDisplayController isActive]) {
          indexPath = [self.searchDisplayController.searchResultsTableView
                          indexPathForSelectedRow];
          destViewController.lodgeName = [filteredList objectAtIndex:indexPath.row];



      } else {
          indexPath = [self.tableView indexPathForSelectedRow];
          destViewController.lodgeName = [lodgeList objectAtIndex:indexPath.row]; 
        }
      }
   }

Example of the switch:

  self.title = lodgeName;     
  switch (lodgeNumber) {
      case 0:
          //Abingdon Lodge No. 48
          address.text = @"325 W Main Street Abingdon, Virginia 24210";
          website.text = @"http://www.grandlodgeofvirginia.org/lodges/48/";
          statedc.text = @"Abingdon Lodge No. 48 holds it's stated communication on the              
                           2nd Monday of the month at 7:30 PM. If there are
                            any exceptions to the regular meeting day or time, 
                            they are posted on the Lodge website.";

         lodgehistory.text = @"According to the earliest records the Abingdon Lodge had 
              its origin “At a meeting held at the house of
              James White in the town of Abingdon, on October 3, 1796.” The record
              states that a dispensation had been given by the Grand Master of
              Masons in Virginia and the following were present: William King,
              Master; Daniel Murphy, Past Master; Robert Johnson, Past Master;
              Charles Carson, Past Master, and William Preston Skillern. For more
              information on the Lodge History please see the Lodge website.";

         break;

Solution

  •     MOVDetailViewController *MDVC = segue.destinationViewController;
    NSIndexPath * path = [self.tableView indexPathForSelectedRow];
    NSString * thelodge = [filteredList objectAtIndex:path.row];
    
    MDVC.lodgeName = thelodge;
    MDVC = [segue destinationViewController];  // REMOVE THIS LINE
    MDVC.lodgeNumber = path.row;