我正在尝试使用下面的代码将一个子视图控制器以编程方式添加到从故事板创建的当前视图控制器中:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
LogInTutorialViewController *lvc = [[LogInTutorialViewController alloc] init];
lvc = (LogInTutorialViewController *)[storyboard instantiateViewControllerWithIdentifier:@"LogInTutorialViewControllerID"];
[self displayContentController:lvc];
- (void) displayContentController: (LogInTutorialViewController*) content;
{
//add as childViewController
[self addChildViewController:content];
[content didMoveToParentViewController:self];
[content.view setFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[self.view addSubview:content.view];
}
看起来至少在模拟器上显示了视图,但是在控制台中我得到了很多错误:
<Error>: CGContextSaveGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
还有相同的描述但是不同的错误:
CGContextSetLineWidth、CGContextSetLineJoin、CGContextSetLineCap、CGContextSetMiterLimit、CGContextSetFlatness、CGContextAddPath、CGContextDrawPath、CGContextRestoreGState,所有这些错误都被记录了两次。
有人知道我做错了什么吗?
我也读了一些帖子,在一些帖子中建议在传递数据之前分配和初始化视图控制器,我也尝试过了,但没有任何运气。
LogInTutorialViewController *lvc = [[LogInTutorialViewController alloc] init];
,因为你是从故事板实例化的。至于错误,请查看下面的答案,我认为你的顺序不正确。 - GoodSp33d