-(void)btnclick1:(UIButton *)sender
{
NSString *storyboardName=@"Main";
UIStoryboard* storyboard1 = [UIStoryboard storyboardWithName:storyboardName
bundle:nil];
secondViewController *add = [[secondViewController alloc]init];
add =[storyboard1 instantiateViewControllerWithIdentifier:@"nextseg"];
[self.view addSubview:add.view];
[self presentViewController:add
animated:YES
completion:nil];
}
我收到错误:原因:'故事板()不包含带有标识符'nextseg'的视图控制器<'
答案 0 :(得分:0)
您需要在XIB的MainStoryboard设置中为要使用的xib设置Storyboard ID
,请参阅图像。在您的情况下,它应该是@"nextseg"
希望这有帮助。
干杯。
答案 1 :(得分:0)
只需将[NSBundle mainBundle]添加到您从中获取故事板的bundle参数。希望这有帮助
-(void)btnclick1:(UIButton *)sender
{
NSString *storyboardName=@"Main";
UIStoryboard* storyboard1 = [UIStoryboard storyboardWithName:storyboardName
bundle:[NSBundle mainBundle]];
secondViewController *add = [[secondViewController alloc]init];
add =[storyboard1 instantiateViewControllerWithIdentifier:@"nextseg"];
[self.view addSubview:add.view];
[self presentViewController:add
animated:YES
completion:nil];
}
还要确保你有一个标识符&#34; nextseg&#34;为您的视图控制器。 &#34; nextseg&#34;不应该是通向视图控制器的segue的标识符,但它应该是视图控制器