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

116 Views Asked by At

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.

4

There are 4 best solutions below

4
dahiya_boy On BEST ANSWER

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.

0
AudioBubble On

If you don't want to use a segue you should create your destination controller by code:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    destinationcontroller *loading = (destinationcontroller *)[self.storyboard instantiateViewControllerWithIdentifier:@"destinationcontroller"];
    [self.navigationController pushViewController:loading animated:YES];
}
3
kalpesh satasiya On

Follow this code:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
       [self performSegueWithIdentifier:@"Your Segue Name" sender:self];

}

pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.

if ([segue.identifier isEqualToString:@"Your Segue Name"]) {
    DetailViewController *vc= (DetailViewController *)segue.destinationViewController;
    NSIndexPath *indexPath = [tableview indexPathForSelectedRow];
    vc.(DetailViewController Object)= [(Your tableView Array name) objectAtIndex:indexPath.row];
    }
}
1
M Zubair Shamshad On

In your case the storyboard ID is RecipeBookViewController

You have to set Storyboard ID for that View controller as explained below.

GO In Xcode utilities pan click on Identity Inspector and set

Storyboard ID = RecipeBookViewController

For more clarification see the Image, and add RecipeBookViewController against Storyboard ID

enter image description here