作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 View Controller 类的静态库。
如何在 Xcode 中创建新项目 包含静态库后 (和标题)我可以调用这个 viewController 吗?
在静态库上查看 Controller :
#import "VC.h"
@interface VC ()
@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIWindow *window;
@end
@implementation VC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_window.backgroundColor = [UIColor whiteColor];
[self.view addSubview: _window];
[super viewDidLoad];
self.label = [[UILabel alloc] initWithFrame:CGRectMake(115.0f, 150.0f, 200.0f, 30.0f)];
self.label.text = @"hello world!";
[self.view addSubview:self.label];
// Do any additional setup after loading the view.
}
@end
VC *vc = [[VC alloc] init];
[self presentViewController:vc animated:YES completion:nil];
最佳答案
有几种方法可以做到这一点。我想说最简单的方法就是简单地将您的 viewControllers .xib 或 storyBoard 作为文件包含在库的文件夹中。如果没有充分的理由让用户无法访问它,那应该不是什么大问题。
另一种方法是使用 universal framework制作你的图书馆。这将在您编译它时为您返回两个框架,一个带有后缀 .framework,另一个带有后缀 .embeddedframework。后者将链接到您的资源。
最后的方法是include it in your project as a bundle .与上述过程相比,这是一个有点复杂且不直观的过程。
编辑:
如果您不使用 Storyboard 或 .xib 文件执行此操作,则需要实际分配和初始化 self.view。它不是从 Storyboard 中加载的,因此您需要自己加载。这就是这段代码的问题。
关于ios - 如何从 Xcode 的静态库中打开 viewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19389558/
我是一名优秀的程序员,十分优秀!