1

ナビゲーション バーのタイトル ビューをカスタマイズしようとしていますが、エラーが発生します。関連するコードは次のとおりです。

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.'

問題は何ですか?

はい、私のプロジェクトには自動レイアウトが必要です。

4

1 に答える 1

0

この質問を見てください:制約を使用してプログラムで titleView を構築する (または一般的に制約を使用してビューを構築する)

フレームを設定しないと、タイトル ビューは x と y がその親に関連していることを認識しません。

于 2013-07-03T18:48:18.467 に答える