我有一个基于故事板的项目
我需要调用一个基于Xib的UIViewController类。
如何从故事板调用Xib类,反之亦然?
答案 0 :(得分:1)
我在Storybboard.SecondViewController中有3个controllers.ViewController和ThirdViewController是XIB部分。
首先我从故事板中调用XIB
ViewController.m
#import "ViewController.h"
#import "SecondViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)actionGoXIB:(id)sender
{
SecondViewController *secondVC = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondVC animated:YES];
}
现在我从XIB打电话给Stoyboard
如果您想要实现此目的,请首先转到Storyboard单击ThirdViewController
点击 - > Identity Inspector
然后点击 - >身份
现在将Storyboard ID设置为Identity中的ThirdViewController 节
请参阅下面的屏幕截图
SeconViewController.m
#import "SecondViewController.h"
#import "ThirdViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (IBAction)actionGoStoryboard:(id)sender
{
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ThirdViewController *thirdVC = [mainStoryBoard instantiateViewControllerWithIdentifier:@"ThirdViewController"];
[self.navigationController pushViewController:thirdVC animated:YES];
// [self presentViewController:thirdVC animated:YES completion:nil];
}