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.
Asked
Active
Viewed 113 times
1
-
can you show some code of tableview methods that what you have done in your side ? – Nirav Kotecha Jan 03 '18 at 05:35
-
Unless you have a very specific reason to use such old tools, you really should be using Xcode 9. – rmaddy Jan 03 '18 at 05:36
-
for the tableview methods, i simply followed the ones in the linked tutorial. also, i'm using xcode 7 because it's what's installed in the available workpc and we're not allowed to download/upgrade unless advised by admin :/ – xjm Jan 03 '18 at 05:44
4 Answers
3
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

M Zubair Shamshad
- 2,741
- 3
- 23
- 45
2
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];
}
}

kalpesh satasiya
- 799
- 8
- 18
-
there's an error message that pops up saying "no known class method for selector "indexPathForSelectedRow" – xjm Jan 03 '18 at 06:19
-
@xjm NSIndexPath *indexPath = [(Your tablevview name) indexPathForSelectedRow]; – kalpesh satasiya Jan 03 '18 at 06:24
-
1
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.

dahiya_boy
- 9,298
- 1
- 30
- 51
-
i tried doing this but xcode pops up an error. it says "Use of undeclared identifier (for the destination view controller)" and "property "perform segue with identifier" not found on object of type "RecipeBookViewController" – xjm Jan 03 '18 at 05:47
-
@xjm make sure your `segue_key` must match with the storyboard. And you have imported `RecipeBookViewController` in your FirstVC. – dahiya_boy Jan 03 '18 at 05:49
-
there are no error messages appearing now but clicking on an item just redirects me back to the current page – xjm Jan 03 '18 at 06:43
-
1
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];
}

clemens
- 16,716
- 11
- 50
- 65