First, Nsclassfromstring is the method of NSObjCRuntime.h
Foundation_export Class __nullable nsclassfromstring (NSString *aclassname);
Description class class.
Parameters: Aclassname The name of a class
Returns: The Class object named by Aclassname, or nil if not class by, then name is currently loaded
Create a class from nsclassfromstring, you can create subclasses using the Richter substitution principle area
Suppose there is a class named: DBHelper
Generally create her instance:
[[DBHelper alloc] init];
However, if you create an entity with nsclassfromstring:
@" DBHelper " Class = nsclassfromstring (className); if (class) { class. New; @" DBHelper " ; ID dbhelperobj = [[Nsclassfromstring (ClassName) alloc] init];
The obvious benefits of this writing are:
1. When using, do not worry because the class does not exist and error, because the return empty time is nil, so does not cause the program to crash
2. A model for convenient use of the Richter substitution principle
Second, in the custom UIView (hex) of the control class, how to get her current Uiviewcontroller tips
1. First, make sure that the class you create inherits from UIView
2. Second, we all know that most of the Uikit classes inherit from Uiresponder.
What is Uiresponder?
There are a number of ways we are familiar with Uiresponder:
1 "Nextresponder
-(Uiresponder * _nullable) nextresponderDescription: Returns the receiver'?? s next responder, or nil if it has none. Object inch Event for handling. Returns: Object inch Event for handling.
2. Actions in the response chain
-(BOOL) Canbecomefirstresponder; // default is NO- (BOOL) Becomefirstresponder; -(BOOL) Canresignfirstresponder; // default is YES- (BOOL) Resignfirstresponder; -(BOOL) Isfirstresponder;
3 "Touch Event
-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Nullable uievent *)event; -(void) touchesmoved: (Nsset<uitouch *> *) touches withevent: (Nullable uievent *)event; -(void) touchesended: (Nsset<uitouch *> *) touches withevent: (Nullable uievent *)event; -(void) touchescancelled: (Nullable nsset<uitouch *> *) touches withevent: (Nullable uievent *)Event ; -(void) touchesestimatedpropertiesupdated: (Nsset * _nonnull) touches Ns_available_ios (9_1);
etc.
3. So we use the Nextresponder method in Uiresponder
for (UIView * view = self; view; view = View.superview) { * nextresponder = [view Nextresponder]; if class ]] { return (Uiviewcontroller *) nextresponder; } }
In fact, there are ways to go back to the view, you can try to write
Nsclassfromstring and Traverse UIView to get tips for her uiviewcontroller