应用程序试图在 didSelectRowAtIndexPath 中将一个 nil 视图控制器推送到目标上

Application tried to push a nil view controller on target in didSelectRowAtIndexPath

我们有两个UIViewControllers

。当我们点击 the UItableViewCell 时,我们希望它转到 SecondViewController

我们这样试过

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

   destinationController = [[UserDetails alloc] init];
   destinationController = (UserDetails *)[storyboard instantiateViewControllerWithIdentifier:@"User"];
   destinationController.FriendlyName.text=[usernameFriendlyName objectAtIndex:indexPath.row];
   UIBarButtonItem * backButton =[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:nil];
   destinationController.navigationItem.backBarButtonItem = backButton;
  [self.navigationController pushViewController:destinationController animated:TRUE];
}

请指导我们。我们的代码有什么问题。

不需要做这一切。只需将两个 viewController 与 Push segue 连接起来。 为 segue 提供一些标识符,然后将这一行简单地写在 didSelectRowAtIndexPath

[self performSegueWithIdentifier: @"Your segue identifier" sender: self];

要将数据从一个视图传递到另一个视图,请使用 PrepareForSegue 方法

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"Your segue identifier"])
    {
        // Get reference to the destination view controller
        YourViewController *vc = [segue destinationViewController];

        // Pass any objects to the view controller here, like...
        [vc setMyObjectHere:object];
    }
}