【发布时间】:2016-12-10 03:25:47
【问题描述】:
我有一个基于故事板的项目
我需要调用一个基于 Xib 的 UIViewController 类。
如何从情节提要中调用 Xib 类,反之亦然?
【问题讨论】:
-
检查我的答案 iphonemaclover
标签: objective-c xcode storyboard xib
我有一个基于故事板的项目
我需要调用一个基于 Xib 的 UIViewController 类。
如何从情节提要中调用 Xib 类,反之亦然?
【问题讨论】:
标签: objective-c xcode storyboard xib
我在 Storybboard 中有 3 个控制器。ViewController 和 ThirdViewController。SecondViewController 是 XIB 部分。
首先我从 Storyboard 调用 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 中将 Storyboard ID 设置为 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];
}
【讨论】: