title: iOS Segue opening two view controllers (assuming two table cells clicked)
body: <p>When I click a table cell in my application it opens two view controllers. Which it seems to assume that I have clicked two cells, since it opens the cell before and the one I have clicked.</p>
  
  <p>The first 3 cells are pretty much static, every other cell underneath the "ingredients" heading are dynamic. Hence why indexPath - 3</p>
  
  <p>I created the segue between the table view and the view controller in the interface builder.</p>
  
  <p>Table View:</p>
  
  <p><img src="https://i.stack.imgur.com/uC2EL.png" alt="enter image description here"></p>
  
  <p>First view controller/segue:</p>
  
  <p><img src="https://i.imgur.com/SNnhhMl.png" alt="enter image description here"></p>
  
  <p>Second view controller segue:</p>
  
  <p><img src="https://i.stack.imgur.com/I0JqX.png" alt="enter image description here"></p>
  
  <p>Code for the segue:</p>
  
  <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
      self.selectedIngredient =  self.selectedProduct.ingredientsArray[indexPath.row - 3];
      [self performSegueWithIdentifier:@"ingViewSegue" sender:self];
      NSLog(@"selected ingredient %@", self.selectedIngredient);
   }
  
    #pragma mark segue
  
   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
       IngredientWebViewController *webView = segue.destinationViewController;
       webView.selectedIngredient = self.selectedIngredient;
   }
  </code></pre>
  
  <p>Number of rows in table:</p>
  
  <pre><code>#pragma mark - Table view data source
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
         return 1;
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
     return [_selectedProduct.ingredientsArray count] + 3;
  }
  </code></pre>
  
  <p>Code to populate table:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if(indexPath.row == 0)
      {
          TitleCell* titleCell = (TitleCell*)[self.tableView dequeueReusableCellWithIdentifier:@"TitleCell" forIndexPath:indexPath];
          titleCell.nameLabel.text = self.selectedProduct.productName;
          titleCell.brandLabel.text = self.selectedProduct.productBrand;
          return titleCell;
      }
      else if(indexPath.row == 1)
      {
          return [self.tableView dequeueReusableCellWithIdentifier:@"RatingCell" forIndexPath:indexPath];
  
      }
      else if(indexPath.row == 2)
      {
          return [self.tableView dequeueReusableCellWithIdentifier:@"IngredientHeaderCell" forIndexPath:indexPath];
      }
      else
      {
          IngredientsCell* ingCell = (IngredientsCell*)[self.tableView dequeueReusableCellWithIdentifier:@"IngredientCell" forIndexPath:indexPath];
  
          ingCell.ingredientNameLabel.text =     self.selectedProduct.ingredientsArray[indexPath.row - 3];
  
          if([self.selectedProduct.ratingsArray[indexPath.row -3]  isEqual: @"4"])
          {
              ingCell.ingredientsImage.image = [UIImage imageNamed:@"icon_safe.png"];
          }
          else if([self.selectedProduct.ratingsArray[indexPath.row -3]  isEqual: @"3"])
          {
              ingCell.ingredientsImage.image = [UIImage imageNamed:@"icon_low.png"];
          }
          else if([self.selectedProduct.ratingsArray[indexPath.row -3]  isEqual: @"2"])
          {
              ingCell.ingredientsImage.image = [UIImage imageNamed:@"icon_med.png"];
          }
          else if([self.selectedProduct.ratingsArray[indexPath.row -3]  isEqual: @"1"])
          {
              ingCell.ingredientsImage.image = [UIImage imageNamed:@"icon_high.png"];
          }
          else
          {
              ingCell.ingredientsImage.image = [UIImage imageNamed:@"icon_safe.png"];
          }
  
          return ingCell;
      }
  }
  </code></pre>
  
  <p>Code to alter cell height:</p>
  
  <pre><code>-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      if(indexPath.row == 0)
      {
         UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"TitleCell"];
         CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
         return size.height + 1;
     }
     else if(indexPath.row == 1)
     {
         UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"RatingCell"];
         CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
         return 118;
     }
     else if(indexPath.row == 2)
     {
         UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"IngredientHeaderCell"];
         CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
         return size.height + 1;
     }
     else
     {
         UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"IngredientCell"];
         CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
         return 60;
     }
   }
  </code></pre>