我知道周围也有同样的问题。但尚未找到任何解决方案。参见下面的代码,我在viewdidLoad中添加一个子视图,并且此控制器在Popover中呈现。
因此,在应用这些约束时,我会收到此错误Unable to interpret '|' character, because the related view doesn't have a superview
-(void) viewDidLoad
{
self.profileHeaderView = [[DSProfileHeaderView alloc] initWithFrame:CGRectZero];
[self.headerView addSubview:self.profileHeaderView];
[self.headerView setAccessibilityIdentifier:@"btnYourProfile"];
self.profileHeaderView.translatesAutoresizingMaskIntoConstraints = false;
self.profileHeaderView.backgroundColor = [UIColor whiteColor];
if (self.viewLoaded) {
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:@{ @"view": self.profileHeaderView }]];
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:@{ @"view": self.profileHeaderView }]];
}
//[self.profileHeaderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[view]-0-|" options:0 metrics:nil views:viewsDictionary]];
//[self.profileHeaderView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[view]-0-|" options:0 metrics:nil views:viewsDictionary]];
}