Objective-C,故事板:instantiateViewControllerWithIdentifier 返回 nil [英] Objective-C, Storyboard: instantiateViewControllerWithIdentifier returns nil
问题描述
我有一个 UITableViewController,它带有一个故事板推送转场,从原型单元链接到一个详细信息页面,一个普通的旧 UIViewController.在storyboard中,detail ViewController有一个标识符,segue有一个标识符,除了第一个字母是小写外,其他标识符与detail标识符相同.此外,细节 ViewController 在类下拉菜单中选择了一个自定义类"(AttractionDetailViewController
).
I have a UITableViewController with a storyboard push segue linking from the prototype cell to a detail page, a regular old UIViewController. In the storyboard, the detail ViewController has an identifier, and the segue has an identifier which is the same as the detail identifier except that the first letter is lowercase. Furthermore, the detail ViewController has a "custom class" (AttractionDetailViewController
) selected in the class pulldown.
不起作用.问题是 instantiateViewControllerWithIdentifier:@"AttractionDetails
返回 nil
.
Doesn't work. The problem is that instantiateViewControllerWithIdentifier:@"AttractionDetails
returns nil
.
相关代码.首先是调试器从未进入的 prepareForSegue
方法.
Relevant code. First the prepareForSegue
method which the debugger has never entered.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"attractionDetails"])
{
AttractionDetailViewController *attrDetailVC = [segue destinationViewController];
}
}
而是进入这个方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//AttractionDetailViewController *attrDetailVC = [[AttractionDetailViewController alloc] init];
AttractionDetailViewController *attrDetailVC = [self.storyboard instantiateViewControllerWithIdentifier:@"AttractionDetails"];
NSIndexPath *selIndexPath = [self.tableView indexPathForSelectedRow];
attrDetailVC.theAttraction = [attractions objectAtIndex:indexPath.row];
[self.navigationController pushViewController:attrDetailVC animated:YES];
}
由于 instantiateViewControllerWithIdentifier
返回 nil
它当然会抛出异常.真正有趣的是,如果我改用 alloc init
行,它可以工作,但屏幕全黑.
Since instantiateViewControllerWithIdentifier
returns nil
it throws an exception of course. The really interesting thing is, if I use the alloc init
line instead, it works, but the screen is all black.
无论如何,我已经阅读了有关此内容并尝试了一些不同的方法,但仍然受阻.有人有什么建议吗?
Anyway, I've read up about this and tried a few different things and I'm still stymied. Does anyone have any suggestions?
推荐答案
问题是你没有从故事板实例化你的主视图控制器(UITableViewController
),所以它的 storyboard
属性为零.
The problem is that you didn't instantiate your master view controller (the UITableViewController
) from the storyboard, so its storyboard
property is nil.
这篇关于Objective-C,故事板:instantiateViewControllerWithIdentifier 返回 nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!