问题描述
我必须以编程方式创建一个segue但是当我点击按钮时,视图控制器不会更改为下一个,故事板ID已设置且仍然无法正常工作。我是否缺少任何其他支票才能使其正常工作?
I have to created a segue programmatically however when I click on the button the view controller does not change to the next, Storyboard ID is set and still not working. Am I missing any other checks in order to make this work?
请参阅以下代码:
EntryViewController *entryController = [self.storyboard instantiateViewControllerWithIdentifier:@"go"];
[self.navigationController pushViewController:entryController animated:YES];
它让我发疯。谢谢
推荐答案
在我的viewDidLoad中,我放置了调用goldStarOpen的按钮:
Inside my viewDidLoad I have placed the button which calls goldStarOpen:
UIButton *btnTwo = [UIButton buttonWithType:UIButtonTypeCustom];
btnTwo.frame = CGRectMake(250, 20, 40, 40);
[btnTwo addTarget:self action:@selector(goldStarOpen) forControlEvents:UIControlEventTouchUpInside];
[btnTwo setImage:[UIImage imageNamed:@"GoldStar.png"] forState:UIControlStateNormal];
[self.view addSubview:btnTwo];
在goldStarOpen里面,我的代码几乎与你的相同。
Inside goldStarOpen I have code which is almost identical to yours.
- (void)goldStarOpen
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:
@"MainStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *myController = [storyboard instantiateViewControllerWithIdentifier:@"GoldStar"];
[self presentViewController:myController animated:YES completion:nil];
}
goldStarOpen激活故事板中的ViewController。
goldStarOpen activates a ViewController in the storyboard.
您可能需要设置要加载的View Controller的Storyboard ID。它位于检查器中,就在您为视图控制器指定自定义类的位置下方。
You may need to set the Storyboard ID of the View Controller you are trying to load. This is located in the inspector, just below where you assign a custom class to your view controller.
这篇关于instantiateViewControllerWithIdentifier - 故事板ID设置但仍然无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!