需要左值作为赋值的左操作数
我想将suitSize 分配给scrollButton 我做错了什么?
UIView *scrollButton = [suitScrollView viewWithTag:1];
CGSize suitSize =CGSizeMake(10.0f,10.0f);
(UIButton *)scrollButton.frame.size=suitSize;
I want to assign suitSize to scrollButton what I'm doing wrong?
UIView *scrollButton = [suitScrollView viewWithTag:1];
CGSize suitSize =CGSizeMake(10.0f,10.0f);
(UIButton *)scrollButton.frame.size=suitSize;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当处理结构体的属性时,您不能以这种方式直接设置子结构体...
UIButton 的frame 属性是一个CGRect 结构体。编译器会看到您的 .size 访问并尝试将其解析为不存在的 setter。您需要将 CGRect 结构类型作为一个整体来处理,而不是将结构成员访问与属性访问器混合在一起......
When dealing with properties that are structs you cannot directly set sub-structs in this manner...
The frame property of the UIButton is a CGRect struct. The compiler sees your .size access and tries to resolve it to a setter which does not exist. Instead of mixing struct member access with property accessors you need to deal with the CGRect struct type as a whole...
框架是一个属性,而不是结构字段。您不能分配给它的子字段。将其视为函数调用;属性的点语法很方便。
这:
相当于:
哪个不起作用;分配给函数结果的字段没有任何意义。
相反,请执行以下操作:
或者,如果您愿意:
请注意,无需将scrollButton 转换为UIButton;只需将scrollButton 转换为UIButton 即可。 UIView 也有框架。
frame is a property, not a structure field. You can't assign to a subfield of it. Think of it as a function call; dot syntax for properties is convenience.
This:
Is equivalent to:
Which doesn't work; it doesn't make any sense to assign to a field of a function result.
Instead, do this:
Or, if you prefer:
Note that casting the scrollButton to a UIButton isn't necessary; UIViews have frames, too.
不要在赋值的左侧混合属性访问器和结构字段访问。
左值是可以出现在赋值左侧的表达式。当混合结构和属性时,生成的表达式不是左值,因此不能在赋值的左侧使用它。
scrollButton.frame
部分是属性访问。.size
部分访问frame
结构的字段。 Steven Fisher 上面的例子是分解代码以避免问题的正确方法。Don't mix the property accessors and struct field access on the left side of an assignment.
An lvalue is an expression that can appear on the left side of an assignment. When you mixstructs and properties, the resulting expression is not an lvalue, so you can't use it on the left side of an assignment.
The
scrollButton.frame
part is a property access. The.size
part accesses a field of theframe
structure. Steven Fisher's example above is the right way to break up the code to avoid the problem.