Sagit.Framework For IOS development framework tutorial 11: controller base class STController


In the Sagit framework, all new controllers and UI views need to inherit from the base class of the framework. This article introduces the base class of the controller: STController

STController: basic definition

#import <UIKit/UIKit.h>
#import "STEnum.h"

@class STView;
@class STHttp;
@class STMsgBox;

@interface STController : UIViewController<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
//!Current controller STView Root view
@property (nonatomic,retain) STView* stView;
//!Used to initiate http request
@property (nonatomic,retain) STHttp *http;
//!For pop-up prompt message
@property (nonatomic,retain) STMsgBox *msgBox;

#pragma mark There are three common event methods: onInit,initUI,initData(There is also one in the base class: reloadData)
//!Event in UI Execute before initialization
//!UI initialization
//!Event in UI Execute after initialization
//!implement view of stValue attribute
//!implement view of stValue attribute
-(void)stValue:(NSString*)name value:(NSString*)value;

//!Verify that the value of the text box is filled in or formatted incorrectly ui of name Processing
-(BOOL)isMatch:(NSString*)tipMsg name:(NSString*)name;
-(BOOL)isMatch:(NSString*)tipMsg name:(NSString*)name regex:(NSString*)pattern;
//!Verify whether the value of the text box is filled in or formatted incorrectly according to the obtained value Processing
-(BOOL)isMatch:(NSString*)tipMsg value:(NSString*)value;
-(BOOL)isMatch:(NSString*)tipMsg value:(NSString*)value regex:(NSString*)pattern;

//!Pop up a message according to the specified result.
-(BOOL)isMatch:(NSString*)tipMsg isMatch:(BOOL)result;
//!point view of setToAll: Batch assign the specified data to all UI Medium: data It can be a dictionary or a dictionary json,Are entities, etc
//!point view of formData:  from UIList Get properties through isFormUI Form data list
//!point view of formData:  from UIList Get properties through isFormUI Form data list  superView : Specify a parent view, otherwise it is the root view


The base class mainly defines the following categories:

1. Common tool class definitions:

STMsgBox and STHttp (these two classes can also be called by self.XXX in the controller in addition to Sagit.XXX.)




2. Initialization events: onInit, onInitUI, onInitData

onInit and onInitUI events are related to UIView, because the core simplification mechanism of the framework is the reason.

Normally, there are four files in a page:





The Sagit framework eliminates the first three files and only needs xxxcontroller M is enough.


Simplified xxxcontroller The definition in H is written directly to xxxcontroller M.

The controller base class defines the initial function of the UI, which can directly initialize the UI code.


Generally, when you need to set the status bar, navigation bar and global settings, set the insurance in this function. If the onInitUI setting is, the global may not take effect.


It is used to initiate a network request, obtain the request data, and further operate the UI interface.

3. Matching verification of forms: isMatch

Used to verify the type or mandatory of the dictionary:

Example code:



XXX Cannot be empty.

XXX Format error.

Final prompt: the mobile number cannot be empty, and the mobile number format is wrong. 


4. Batch value submission of forms: formData

For some personal data filled in, you can submit them in batch, eliminating the value one by one.

Example code:


When you click Save event, the framework will automatically collect the form content and submit it. Example code:


Get the content of the current form, which is a dictionary.

Other parameters can be added, such as longitude, latitude and other parameters that are not presented in the form.

5. Batch automatic assignment of forms: setToAll

Or the interface above:

Restore loaded code example:



There are three setToAll receive parameters:

1,Json character string


3,Inherited from STModelBase Entity class

6. Field value and assignment of a single UI: stValue

Take value or assign value according to the name of UI control.


Other: core loading reasons:

    //Gets the current class name
    NSString* className= NSStringFromClass([self class]);
    NSString* viewClassName=[className replace:@"Controller" with:@"View"];
    Class viewClass=NSClassFromString(viewClassName);
        self.view=self.stView=[[viewClass alloc] initWithController:self];
        //[self.stView loadUI];
    {   //This step, in ViewController Medium loadView Processed by default self.view namely STView
        self.view=self.stView=[[STView alloc] initWithController:self];//take view change into STView
    [self initUI];

XXXController # initialization:

1,Will you find it first XXXView If any, initialize it as its own default view.

2,If you don't have an empty view, you can create one by default.

That's all for this article.

Tags: iOS

Posted by ethan89 on Tue, 24 May 2022 17:35:03 +0300