IOS UI basics 03, iosui03

Source: Internet
Author: User

IOS UI basics 03, iosui03

  • Plist File
    • Root: What type of data is stored
      If the root is an array, all items in the plist array will be read from the file in the future. Each item in the plist array represents the type of an element item in the array and represents the type of each element in the array.
    • The name of the custom plist file cannot contain the word info, because the system configuration is info. plist.
    • Obtain the plist file path
      • NSString * path = [[NSBundle mainBundle] pathForResource: @ "shops. plist" ofType: nil];
  • Dictionary-to-Model

    • Cause:

      • Generally, data is not directly retrieved from the dictionary during development.

        • 1. The dictionary key is a string and no error is reported when an error is written.
        • 2. Words cannot be remembered due to poor English
        • 3. Because the key is a string, no prompt is prompted During encoding.
      • To solve this problem, we can use an object to save data. The object is used to store data, so I call this object a model.

      • Rule: during development, whenever you see a dictionary, a corresponding model is usually created to save the data in the dictionary.
      • You cannot use kvc to convert dictionary arrays.
      • General steps:
        • 1. Obtain the absolute path of the plist File
        • 2. Load the plist file by path
        • 3. convert all the dictionaries in the array to the model.
  • Custom VIEW

    • To customize a View, follow these steps:
      • 1. Override the initialization method (one-time initialization in it) xib: awakeFromNib pure code: initWithFrame
      • 2. Override layoutSubviews and layout the child controls in it
      • 3. Receive incoming data and rewrite the set method.
    • Note:
      • If you customize a View, it is not recommended to set the position of the child control in the init method. Because if the position of the child control needs to be calculated based on the frame of the parent control, the frame of the parent control cannot be obtained in the init method.
    • Note:
      • Generally, customizing a control will overwrite the initWithFrame method of the control, because the user may create it through the init method or the initWithFrame method, to ensure that sub-controls can be added no matter which method the user creates, the initWithFrame method calls initWithFrame internally to override initWithFrame.
    • Note:
      • If you create an object in the class method, we recommend that you use self instead of the class name. If you use the class name directly, the parent class is dead when the child class is present, therefore, you cannot use this method to create a subclass object.
    • LayoutSubviews
      • Used to layout the position of child Controls
      • To override the layoutSubviews method, you must call the [super layoutSubviews] method. If you do not call this method, some strange errors may occur.
    • Rewrite model set
      • Set the data of the Child Control
  • Reasons for saving the control using week:

    • As long as an object is added to the parent control, the subViews array in the parent control will strongly reference this control.
  • Xib
    • Both Xib and Storyboard are used to describe the interface.
    • Xib is the predecessor of Storyboard
    • Xib is used to describe a simple interface or a local interface.
    • Storyboard is used to describe the whole
    • Obtain the Xib Method
    • NibName: The xib name bundle to be loaded: from which package to find
    • -1. UINib * nib = [UINib nibWithNibName: @ "ShopView" bundle: [NSBundle mainBundle];-create all interfaces described in xib NSArray * res = [nib instantiateWithOwner: nil options: nil]; [self. shopsView addSubview: res. firstObject]; 2. NSArray * res = [[NSBundle mainBundle] loadNibNamed: @ "ShopView" owner: nil options: nil]; [self. shopsView addSubview: res. firstObject];
    • Xib loading principle:
      • 1. Create an object JXShopView * shopView = [JXShopView alloc] init] based on custom class;
      • 2. Set shopView. backgroundColor = [UIColor redColor]; shopView. frame = CGR ectMake (0, 0, 70,100 );
      • 3. Create all child controls and set attributes of the child controls.
      • UIImageViewIv = [[UIImageView alloc] init];
      • Iv. frame = CGRectMake (0, 0, 70, 70 );
      • UILabelLabel = [[UILabel alloc] init];
      • Label. frame = CGRectMake (0, 70, 70, 30 );
      • 4. Check whether the child control is connected. If yes, associate self. iconView = iv; self. nameLabel = label;
      • 5. Add all child controls to the parent control [shopView addSubview: iv]; [shopView addSubview: label];
    • Note:
      • If you create a control through xib or Storyboard, The initWithFrame method is not called.
      • If you use xib or Storyboard to create a control, the initWithCoder method is called during creation. When you call this method, the control may not be created properly.
      • If you create a control through xib or Storyboard, awakeFromNib is called after the control is created. When you call this method, it indicates that the control has been created.

Related Article

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.