iOS:消息“帧”的接收者为零
当我分析代码时,出现以下逻辑错误:
消息“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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
分析器表示
计算结果为
nil
,因此无法为rectFrame
分配合理的值。您正在使用purchaseCell
及其代码中其他位置的属性做什么?“接收者”是指接收“帧”消息的对象。
看起来可能有一些代码分支,其中单元或其 lblValue 属性可能为零,并且分析器不喜欢它。如果您找不到真正的原因是什么,@StilesCrisis 建议检查 nil 值并返回,如果是的话,可能会为您清除它(并防止任何可能的错误)。
The analyzer is saying that
evaluates to
nil
, so no sensible value can be assigned torectFrame
. What are you doing withpurchaseCell
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.