简体   繁体   中英

self.navigationController pushViewController: animated: gives me a black screen

I'm using Objective-C. I have this code in my .m file.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    detailViewController *detail = [[detailViewController alloc]init];
    [self.navigationController pushViewController:detail animated:YES];
}

And I created my Detail View Controller Scene in storyboard. It looks like this [在此处输入图片说明

And every time I run this in my simulator and tap on one of the tableview cell, it pushes the screen to a complete black screen like this:

在此处输入图片说明

Can someone help me? I would thank you very much!

Yes it will give a blank screen, because you haven't attached any visual interpretation on detailViewController class.

Use this method

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DetailViewController *vc = [sb instantiateViewControllerWithIdentifier:@"detailViewController"];
[self.navigationController pushViewController:vc animated:YES];

You will have to set storyboard id by clicking on view controller and set storyboard id as shown in picture

在此处输入图片说明

Note : for above pic replace Storyboard id "MessagingVC" with "detailViewController"

When using a storyboard, you don't want to use alloc+init to create the view controller. Instead, you need to assign a Storyboard ID in Interface Builder and then use:

[self.storyboard instantiateViewControllerWithIdentifier:my_identifier];

A better option may be to set a push segue on the table view controller. This will cause the instantiation and push to happen automatically. You can override prepareForSegue:sender: to set properties, if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM