错误:不包含带标识符的视图控制器?

时间:2014-10-27 06:40:51

标签: ios xcode5

-(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'的视图控制器<'

2 个答案:

答案 0 :(得分:0)

您需要在XIB的MainStoryboard设置中为要使用的xib设置Storyboard ID,请参阅图像。在您的情况下,它应该是@"nextseg"

enter image description here

希望这有帮助。

干杯。

答案 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的标识符,但它应该是视图控制器