0

当我分析我的代码时,我得到以下逻辑错误:

消息 'frame' 的接收者是 nil,并返回一个类型为 'CGRect' 的值,该值将是垃圾。

在这两行:

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,因此不能为 分配合理的值rectFrame。你在做什么purchaseCell以及它在代码中其他地方的属性?

“接收者”是指接收“帧”消息的对象。

看起来可能有一些代码分支,其中单元格或其 lblValue 属性可能为 nil,而分析器不喜欢它。如果您找不到真正的原因,@StilesCrisis 建议检查 nil 值并返回如果是,则可能会为您清除它(并防止任何可能的错误)。

于 2012-01-25T15:54:45.803 回答