Search code examples
iosobjective-cxcodexcode7

Redirection for detailsVC is not working on click of UITableView's Cell in Xcode 7


I'm trying to make a simple iOS app by following this (https://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/) tutorial but when I try to click on the listed items, I don't get redirected to the detail view and just stay on the same page. I'm fairly new to using both Xcode (I'm using Xcode 7) and objective-C so I have no idea what I'm doing. Any kind of help will be very appreciable.


Solution

  • In appCoda, they used segue to push so you might be not added this code in your project,

      - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
      {
         if ([segue.identifier isEqualToString:@"segue_Key"]) {
          DetailViewController *nextVC = [segue destinationViewController];
    
        }
    }
      - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
     {
        [self performSegueWithIdentifier:@"segue_Key" sender:self];
      }
    

    If you facing issue in segue then remove the segue connection from storyboard and use below code ,

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
             DetailViewController *obj = (DetailViewController *) [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"]; // Identifier must match with the storyboard VC ID, else project git crashed.
    
            [self.navigationController pushViewController:obj animated:YES];
    
        }
    

    If you already done this, then let me know.