質問

XIBファイルで作成されたカスタムTableViewCellでAutoLayoutを使用しています。

ENTER IMENT Description

すべてが予想されるように動作し、正しいが表示されますが、TableViewをスクロールしながらたくさんの警告メッセージが表示されます。

同時に制約を満たすことができません。 おそらく次のリストの少なくとも1つの制約はあなたが望んでいないものです。これを試してください:(1)各制約を見て、あなたが期待していないものを理解しようとします。 (2)不要な制約または制約を追加したコードを見つけて修正してください。 (注:わからないNSAutOredizingMaskLayoutConstraintsが表示されている場合は、UIViewプロパティTranslateSautoResSizingMaskIntroconsItoConstroctsを参照してください。 (

"<NSLayoutConstraint:0xc3970d0 V:[UIImageView:0xc396fc0(75)]>",
"<NSLayoutConstraint:0xc3c1dc0 V:|-(10)-[UIImageView:0xc396fc0]   (Names: '|':UITableViewCellContentView:0xc396f20 )>",
"<NSLayoutConstraint:0xc3c1fc0 V:[UIImageView:0xc3b7700]-(0)-|   (Names: '|':UITableViewCellContentView:0xc396f20 )>",
"<NSLayoutConstraint:0xc3c1ff0 V:[UIImageView:0xc396fc0]-(43)-[UIImageView:0xc3b7700]>",
"<NSAutoresizingMaskLayoutConstraint:0xc3bf8c0 h=--& v=--& V:[UITableViewCellContentView:0xc396f20(126.5)]>"
)

Will attempt to recover by breaking constraint 

<NSLayoutConstraint:0xc3970d0 V:[UIImageView:0xc396fc0(75)]>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in    <UIKit/UIView.h> may also be helpful.
.

特に次の部分は面白いと思います:

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0xc3970d0 V:[UIImageView:0xc396fc0(75)]>
.

だから問題は左上の私のUiimageViewの高さですか?私は身長と他の多くのものを削除しようとしましたが、絶対に注目に瀕しています....私は何ができますか?私は左上の私のUiimageViewのための固定サイズを望みます...

編集: たぶん問題は、一番下のUiimageViewがオプションであり、時にはその隠されたものである可能性があるので、警告の可能性があります...

私のコードの重要な部分:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath{

    static NSString *CellIdentifier1 = @"NewsCell";


    GTNewsCustomCell *newsCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

    NSString *bottomImage = [[self.newsList objectAtIndex:indexPath.section] valueForKey:@"boardnoteImage"];

    if(bottomImage == (NSString *)[NSNull null] || bottomImage == nil || bottomImage.length == 0){

        newsCell.bottomImage.hidden = YES;
        newsCell.bottomImage.image = nil;
        newsCell.bottomConstraint.constant = 0.0f;

        [newsCell layoutIfNeeded];
    } else {

        newsCell.bottomConstraint.constant = 19.0f;
        newsCell.bottomImage.hidden = NO;
        [newsCell layoutIfNeeded];

        [newsCell.contentView addSubview:newsCell.boardNoteImage];

    }


    newsCell.titleLabel.text = [[self.newsList objectAtIndex:indexPath.section]objectForKey:@"title"];

    newsCell.messageText = [[self.newsList objectAtIndex:indexPath.section]objectForKey:@"previewMessage"];

    NSString *authorImg = [[self.newsList objectAtIndex:indexPath.section] valueForKey:@"objectImage"];


    return newsCell;
  }
.

編集2: 私はいくつかの変更を加え、セルの高さ計算は今:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *bottomImage = [[self.newsList objectAtIndex:indexPath.section] valueForKey:@"boardnoteImage"];

//Check if the bottom Image exists
if(bottomImage == (NSString *)[NSNull null] || bottomImage == nil || bottomImage.length == 0){
//        if it not exists the cell should be smaller
    return 128.0f;
}
//if the image exists the size should be 250
return 250;

}
.

編集:3

最後に今動作します。 2つの解決策があります。最初のものは、正直なところ、私のUitextviewからのいくつかの奇妙な挿入器を理解していない正直になるように、セルの高さを148.0fに設定することです。そしてSECNDソリューションは、下の画像の下部制約を削除し、下の画像のフィックス高さを設定することです!

役に立ちましたか?

解決

現在の制約の設定は、下部UIImageViewを-1.5の高さに与える。

オートライアウトの第2課 - あなたはネガティブを持つことができません!

エラーメッセージからこれを見ることができます。

(UiTableViewCellの)から(UiTableViewCellの)最上位から...

  • 10のギャップ。
  • 75の高さ。
  • 43のギャップ。
  • 可変の高さ(これは大きなイメージビューです)
  • 0のギャップ。

これは128まで加えられます。

今、あなたはまた、126.5の上から下への細胞の全身の高さを持っています。

画像ビューの可変高さを-1.5に設定する唯一の方法は、次のとおりです。これはできませんオートライアウトの2番目の規則を壊します。それで、それはそれがそれを助けるかもしれないと思う制約を選択します。したがって、あなたはおそらく0か何かの画像の高さを得るでしょう。

制約を変更するか、セルの高さ128を作る必要があります。

他のヒント

私はサンプルプロジェクトであなたのレイアウトを複製し、私があなたの問題を再現することができる唯一の方法は、これをcellForRowAtIndexPathに設定することによるものでした:

cell.translatesAutoresizingMaskIntoConstraints = NO;
.

あなたがそれをやっているなら、それを取り除いてみてください。私は詳細を掘り下げる時間がありませんでした。しかし、一般的に、テーブルビューはセル自体のレイアウトを所有しているため、良い経験則はこのデフォルト値を変更しないと思います。内容のレイアウトしか所有していません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top