2017-07-31 7 views
0

コレクションビューでサイズ変更ビューを使用して動的なセルサイズを作成しようとしています。NSInvalidArgumentException setSizeHasBeenSet認識できないセレクタ - アトリビュート付きテキスト

すべてがうまくいきます。テキストを使用していても、属性付きテキストに変更するとすべてがクラッシュし、やけどします。

私はその後、私は

func configureCell(promo:CMSPromotion) { 
    if let mainAttributedString = promo.content?.htmlAttributedString() { 
    mainText.attributedText = mainAttributedString 
    } 
} 

セルに私のHTMLをセルクラスで

sizingView.configureCell(promo: promo) 

を自分のダイナミックテキストを送信UIlabel

let sizingView = Bundle.main.loadNibNamed("MyNib", owner: self, options: nil)?[0] as? MyCell 

とnibファイルを持っています帰属しました

// Convert HTML to NSAttributedString 
func htmlAttributedString() -> NSMutableAttributedString? { 
    guard let data = self.data(using: String.Encoding.utf16, allowLossyConversion: false) else { return nil } 
    guard let html = try? NSMutableAttributedString(
     data: data, 
     options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], 
     documentAttributes: nil) else { return nil } 
    return html 
} 

すべてのGoogleで見つかることができるsetSizeHasBeenSetの唯一のリファレンスは_UIFlowLayoutItemですが、なぜこれが適切なのかわかりません。

https://github.com/JaviSoto/iOS10-Runtime-Headers/blob/master/Frameworks/UIKit.framework/_UIFlowLayoutItem.h

私は UICollectionView sizeForItemAt IndexPathで同様の質問を参照してくださいが、提供されているコードは、他の問題を持っているので、審査の上、それは、複製ではありません。

+0

から期待の高さを返す錆びsizeForItemAtIndexPathあなたは全体のエラーメッセージを表示してもらえますか? 「インスタンスに送信された認識できないセレクタ」は、呼び出されたメソッドと不一致のクラスオブジェクトを返します。また、stacktrace? – Larme

答えて

0

問題を回避する方法があります。私は計算が重すぎると思っているので、それは通常のテキストではなく属性付きテキストでは機能しません。

コレクションビューをロードする前にバックグラウンドスレッドですべてのセルの高さを計算しています私は私の配列

func collectionView(_ collectionView : UICollectionView,layout collectionViewLayout:UICollectionViewLayout,sizeForItemAtIndexPath indexPath:IndexPath) -> CGSize { 
関連する問題