iOS:消息“帧”的接收者为零

发布于 2024-12-29 02:28:17 字数 1320 浏览 3 评论 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);

When I analyze my code, I get the following Logic Error:

The receiver of message 'frame' is nil and returns a value of type 'CGRect' that will be garbage.

on these two lines:

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

The code works great, but just trying to figure out what this is saying. Am I doing something wrong?

EDIT: Here is the full method:

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑红尘 2025-01-05 02:28:17

分析器表示

purchaseCell.lblValue

计算结果为 nil,因此无法为 rectFrame 分配合理的值。您正在使用 purchaseCell 及其代码中其他位置的属性做什么?

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

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

The analyzer is saying that

purchaseCell.lblValue

evaluates to nil, so no sensible value can be assigned to rectFrame. What are you doing with purchaseCell and it's properties elsewhere in the code?

The "receiver" means the object that is receiving the "frame" message.

It looks like there is probably some code branch where the cell or its lblValue property could be nil, and the analyser doesn't like it. @StilesCrisis' suggestion of checking for a nil value and returning if so will probably clear it out for you (and prevent any possible error), if you can't find what the real cause is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文