ios-share two small questions

Source: Internet
Author: User

First, the Uiimageview initwithimage: Method

1. QuestionsSee someone discussing why this creates a uiimageview that will not be shown, the code is as follows:Uiimageview* ImageView = [[UiimageviewAlloc]init]; ImageView.Image= [UIImageImagenamed:@ "Icon.png"]; [Self.view addsubview:imageview]; The first eye to see this problem, intuitive to think that the view is no size, certainly cannot be displayed. Later found that the original use of the wrong should be the code as follows:

Uiimageview* ImageView = [[UiimageviewAlloc]Initwithimage:[UIImageImagenamed:@ "Icon.png"]; [Self.View addsubview: ImageView];

run the code manually, really, why do you use this phenomenon?

 

2. Analysis

a Uiimageview is created in two different ways, and the corresponding properties are output:1, with initwithimage: Initialize <UIImageView:0x7fa1ca8225d0; frame = (0 0; opaque = no; userinteractionenabled = no; layer = <calayer: 0x7fa1c8ca2060>>2. Initialize with init<UIImageView:0x7f9b449aa030; frame = (0 0; 0 0); opaque = no; userinteractionenabled = no; layer = <calayer:0x 7f9b4490cfa0>>

 

3. Conclusion

initwithimage: Initialization automatically sets the size of the view, and Init does not set the view size. ii. Local Declaration of ' XXX ' hides instance variable When you write code, you see a code warning:looked for a long time, found that the original was accidentally re-declared a variable with the same name as the member variable, the code is as follows: Summary: So now understand the above warning message is that this variable is overwritten.

ios-share two small questions

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.