0

コードを分析すると、次のロジック エラーが発生します。

メッセージ 'frame' の受信者は nil であり、ガベージになるタイプ 'CGRect' の値を返します。

これらの2行で:

CGRect rectFrame = purchaseCell.lblValue.frame;
CGRect rectFrameBG = purchaseCell.lblValueBG.frame;

コードはうまく機能しますが、これが何を言っているのか理解しようとしているだけです。私は何か間違ったことをしていますか?

編集:完全な方法は次のとおりです。

purchaseCell.lblHeader.font = [UIFont fontWithName:@"AvenirNextLTPro-Regular" size:16];
purchaseCell.lblHeader.text = curField.fieldName;
purchaseCell.lblValue.text = curField.fieldValue;
purchaseCell.lblValueBG.text = curField.fieldValue;
purchaseCell.lblValue.font = [UIFont fontWithName:@"AvenirNextLTPro-Regular" size:16];
purchaseCell.lblValue.backgroundColor = [UIColor clearColor];
purchaseCell.lblValueBG.textColor = [UIColor clearColor];
[purchaseCell.lblValueBG sizeToFit];
[purchaseCell.lblValue sizeToFit];
CGRect rectFrame = purchaseCell.lblValue.frame;
CGRect rectFrameBG = purchaseCell.lblValueBG.frame;
NSLog(@"RectFrame X:  %.2f", rectFrame.origin.x);

purchaseCell.lblValue.frame = CGRectMake(rectFrame.origin.x-rectFrame.size.width,rectFrame.origin.y, rectFrame.size.width+14, rectFrame.size.height);
frameSizeWidth = rectFrame.size.width;
purchaseCell.lblValueBG.frame = CGRectMake(rectFrameBG.origin.x-rectFrameBG.size.width,rectFrameBG.origin.y, rectFrameBG.size.width+14, rectFrameBG.size.height);
4

1 に答える 1

2

アナライザーが言ってる

purchaseCell.lblValue

に評価されるためnil、適切な値を に割り当てることはできませんrectFramepurchaseCellコードの他の場所にあるプロパティで何をしていますか?

「受信者」とは、「フレーム」メッセージを受信して​​いるオブジェクトを意味します。

おそらく、セルまたはその lblValue プロパティが nil になる可能性のあるコード ブランチがいくつかあるように見えますが、アナライザーはそれを好みません。@StilesCrisis の nil 値をチェックし、そうであれば返すという提案は、本当の原因が見つからない場合、おそらくそれをクリアします (そして、考えられるエラーを防ぎます)。

于 2012-01-25T15:54:45.803 に答える