Search code examples
iosobjective-cuitableviewstoryboardpushviewcontroller

iOS - call the method : [self.navigationController pushViewController: animated:], the screen get whole black


I want to push SecViewController by selecting a row in a tableview. I am using Storyboard to implement it. This is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

SecViewController *sec = [[SecViewController alloc] init];
[self.navigationController pushViewController:sec animated:NO];

}

And this is my storyboard: enter image description here

But when I run this app: it appears this situation: ViewController SecViewController

Why is it so?


Solution

  • Change your code as following :

    SecViewController *sec = [self.storyboard instantiateViewControllerWithIdentifier:@"viewControllerIdentifier"];
    
    [self.navigationController pushViewController:sec animated:NO];
    

    Change viewControllerIdentifier as your storyboard identifier for that view controller ..

    Hope it helps..