Nishanth Nishanth - 10 days ago 6
iOS Question

exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: ...can someone please find what is wrong with this


error occurs with below code---Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Could not load
NIB in bundle:


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewController *dvc =[[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:nil];
dvc.index = indexPath.row;
[self.navigationController pushViewController:dvc animated:YES];

}

Answer

As mentioned in your comments you are using Storyboard, then this is not how you will initialize an object of UIViewController with the storyboard.

You must create object like this

DetailViewController *vcDetailViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DetailViewController"];
vcDetailViewController.index = indexPath.row;
[self.navigationController pushViewController:vcDetailViewController  animated:YES];

Also, you need to give StoryBoard Id to your view controller, check image

enter image description here