Model with dictionary 1. The benefits of replacing dictionaries with models
- Disadvantages of using dictionaries
- The compiler does not have the ability to automatically remind you that you need a hand knock
- Key if you write the wrong compiler will not error
2. Model Concepts
- Concept
- Objects specifically used
存放数据
for
- Characteristics
- Generally inherited from NSObject
- Declare some properties in the. h file to hold the data
- Comments
- Single-line Comment
- / /multi-line Comment
- /* /Document comment, the document comment is displayed when the property is called
- Benefits of using Models
- The model sets the data and takes out the data through its properties, the property name if the error is written, the compiler will immediately error, so that the correctness of the data
- When using a model to access properties, the compiler provides a series of hints to improve coding efficiency
3. Nine spaces
- Create steps
- Commodity
- Lazy Loading
- Create a mutable array
- Get the full path of plist
- Get the dictionary data in plist
- Converting a dictionary array into a model array
- To add a model array to the model array
- Add to
- Total number of columns
- Gets the index of the current product
- Set the width and height of the product
- Set the location of the item
- Create a parent control
- To add a parent control to a large view
- Add a picture
- Add text
- Setting up data
- Set the state of a button
- Delete
- Set the state of a button
- [Self.shopsView.subviews.lastObject removefromsuperview];//Delete last element
4. @property Usage Policy
- Assign
- Non-OC object types, such as basic data types, enumerations, structs, etc.
- Weak
- OC object type (e.g. Nsarray,nsdate,nsnumber, model Class)
- Generally used on UI controls
- Strong
- OC object type (e.g. Nsarray,nsdate,nsnumber, model Class)
- An object is not destroyed if it is referenced by a strong reference.
- Copy
- Usually used on Nsstring/block.
5. Create a custom control with pure code
- Inherit from the system's own control, write a control that belongs to you
- Purpose: Encapsulates the details inside the control
- Steps
- To create a new inherited
UIView
class
- To
initWithFrame
add a child control to a method
- The initWithFrame method is automatically called inside Init
- Therefore, the initWithFrame method should be rewritten
layoutSubViews
set the child control's frame in (child control layout)
- Layoutsubviews is called when the size of the space changes
- Be sure to call [Super Layoutsubviews] first;
- Provides a model property that overrides the set method of a model property
- Take the model property out of the set method and assign a value to the corresponding child control
6. Customizing controls by Xib
*views = [[NSBundle mainbundle] loadnibnamed:@ "xib filename " Owner:nil Option:nil];
方法2
uinib*nib = [uinib nibwithnibname:@ "xib filename "*views = [nib Instantiatewithowner: Nil Option:nil];
- Steps
- Create a new custom control class
- New Xib File
- Modify the class name of view in Xib (can only be modified to a class of the same type)
- Loading process for encapsulated Xib
- Drag line
- Add model properties, set data to child controls in the set method of model properties
- Comparison of Xib and storyboard
- Common:
- is used to describe the software interface
- are edited using the Interface Builder tool.
- The essence is to convert the code to create the control
- Different points
- Xib is lightweight and used to describe the local UI interface S Toryboard is heavyweight, used to describe the entire software interface, and can show a jump relationship between multiple interfaces
6. Knowledge points
- If the control is not created by Xib\storyboard, the initWithFrame is called when initialized: (CGRect) frame;
- If created through Xib\storyboard, Initwithcoder: (Nscoder *) Adecoder is called when initializing;
- If created through Xib\storyboard, the awarkfromnib is called when the initialization is complete
- Comparison of Xib and storyboard
7. Class prefixes
- NS-to-Next Step
- UI-User Interface
- AV--Audio Player
plist file
- You can typically use a property list file to store data such as Nsarray or nsdictionary, which has a "property list file" extension of plist and is also known as a "plist file"
1. Parsing the plist file
- Down to parse the data in the Plist file by code
2. Use note
The file name of plist is not called "info" or "info".
When adding file resources such as plist, be sure to tick destination:copy items if needed/added folders:create groups/add to targets: non-test items
plist file and dictionary transfer model