About the error cause of expression is not assignable in OC

Source: Internet
Author: User

This error occurs when we assign a value directly to Self.view.frame.size.height = 100 in OC, the reason for this error is that:

Self.view.frame is the point syntax of objective-c syntax, and the Frame property is a cgrect structure, Frame.size.height is the C language syntax, because OC is only a C language extension, so the above sentence into the C language of the form of conversion will become:
GetFrame (). Size.Height = 100f;

In C, the return value of a function is a r-value, which cannot be directly assigned to him (the so-called R-value, which can only appear on the right side of the equal sign, you may understand it as a constant, but can be assigned to the L-value, which can appear on the left side of the equal sign, usually a variable). This error occurs when you assign a value directly to it. The solution is to add a zero variable to the function, modify the zero variable, and then assign the value to the frame. You can modify the height and width values in the frame.
Example:
1. Saves the return value with a temporary variable. CGRect temp = self.view.frame;//2. Assign a value to the variable. Because the variables are l-value, they can be assigned temp.size.height = 100f;//3. Modify the value of frame self.view.frame = temp;

About the error cause of expression is not assignable in OC

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.