1. nsclassfromstring
This method is used to determine whether a class exists. If a class exists, it is dynamically loaded and an empty object is returned if it is not saved;
Id myobj = [[nsclassfromstring (@ "myspecialclass") alloc] init];
Normally, it is equivalent to: Id myobj = [[myspecialclass alloc] init];
Advantages:
1. The connection is weakened, so no framework is linked to the program.
2. You do not need to use import because classes are dynamically loaded and can be loaded as long as they exist. Therefore, if your toolchain does not have a header file definition for a class and you are sure that this class is usable, you can also use this method.
2.Nsselectorfromstring
This method is a supplement to the previous method and also a method for dynamically loading instances.
Sel sel = nsselectorfromstring (@ "dosomethingmethod:") // note that this colon indicates that the method has a parameter
If ([object respondstoselector: sel]) {
[Object upload mselector: sel withobject: Color]; // If two parameters exist, use two withobject: parameters;
}
3. iskindofclass
Iskindofclass we can also use iskindofclass to check whether an object is a member of a class.
4. ismemberofclass
The ismemberofclass method is used to determine whether an object is a member of a class.
5. differences between initwithcoder and initwithframe initwithcoder is called when a class is created in IB but instantiated in xocdde. for example, if you create a controller NIB file through IB and then instantiate the controller through initwithnibname in xocde, the Controller's initwithcoder will be called.
Initwithframe is a user-created uiview subclass. It is called when an instance is created.
6. uiview autoresizingmask
If the autoresizessubviews attribute declaration of a view is set to yes, its subviews are automatically adjusted based on the autoresizingmask attribute value. Simply configuring the automatic size adjustment mask of the view can often make the application get the appropriate behavior; otherwise, the application must provide its own implementation by reloading the layoutsubviews method.
Self. autoresizingmask = uiviewautoresizingflexiblewidth; // if this constant is set, the width of the view changes proportionally with the width of the parent view. Otherwise, the view width remains unchanged.
Uiviewautoresizingnone |
If this constant is set, the view will not adjust the size automatically. |
Uiviewautoresizingflexibleheight |
If this constant is set, the height of the view will change proportionally to the height of the parent view. Otherwise, the view height remains unchanged. |
Uiviewautoresizingflexiblewidth |
If this constant is set, the width of the view will change proportionally with the width of the parent view. Otherwise, the view width remains unchanged. |
Uiviewautoresizingflexibleleftmargin |
If this constant is set, the left boundary of the view is adjusted proportionally as the width of the parent view changes. Otherwise, the relative position of the left boundary of the view and its parent view remains unchanged. |
Uiviewautoresizingflexiblerightmargin |
If this constant is set, the right border of the view is adjusted proportionally as the width of the parent view changes. Otherwise, the relative position of the right boundary of the view and its parent view remains unchanged. |
Uiviewautoresizingflexiblebottommargin |
If this constant is set, the bottom boundary of the view is adjusted proportionally as the height of the parent view changes. Otherwise, the relative position of the bottom boundary of the view and its parent view remains unchanged. |
Uiviewautoresizingflexibletopmargin |
If this constant is set, the upper boundary of the view is adjusted proportionally as the height of the parent view changes. Otherwise, the relative position of the upper boundary of the view and its parent view remains unchanged. |