[英]iOS: Error when trying to customize Navigation bar
我正在尝试自定义导航栏的标题视图,并收到错误消息。 以下是相关代码:
UIView *topView = [[UIView alloc] init];
topView.translatesAutoresizingMaskIntoConstraints=NO;
self.navigationItem.titleView=topView;
UIImage *image = [UIImage imageNamed: @"logojim_35.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
imageView.translatesAutoresizingMaskIntoConstraints=NO;
[topView addSubview:imageView];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.translatesAutoresizingMaskIntoConstraints=NO;
titleLabel.text=@"ACPL Mobile";
[topView addSubview:titleLabel];
NSDictionary *views = NSDictionaryOfVariableBindings(topView,imageView,titleLabel);
[topView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[imageView]-[titleLabel]|" options:nil metrics:nil views:views]];
这是我得到的错误:
2012-11-13 16:23:51.635 Mobile_ACPL[22177:12b03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UINavigationBar's implementation of -layoutSubviews needs to call super.'
知道是什么问题吗?
是的,我的项目需要“自动布局”。
看一下这个问题: 以约束方式以编程方式构建titleView(或通常以约束方式构建视图)
如果未将其设置为框架,则标题视图不知道x和y与它的父级有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.