Sagit.Framework Introduction to for IOS development framework 11: controller base class stcontroller



In SAGIT framework, all new controllers and UI views need to inherit from the base class of the framework. This paper introduces the base class of controller: stcontroller

Stcontroller: basic definition

#import "STEnum.h"

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

@interface STController : UIViewController
//! stview root view of current controller
@property (nonatomic,retain) STView* stView;
//! for HTTP requests
@property (nonatomic,retain) STHttp *http;
//! for pop-up message
@property (nonatomic,retain) STMsgBox *msgBox;

#Three common event methods of pragma mark: OnInit, initui and initdata
//! event is executed before UI initialization
//! UI initialization
//! event is executed after UI initialization
//! execute the stvalue property of view
//! execute the stvalue property of view
-(void)stValue:(NSString*)name value:(NSString*)value;

//! verify that the value of the text box is filled in or formatted incorrectly, and handle it according to the UI name
-(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, and process it according to the obtained value
-(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 to view settoall: batch assign the specified data to all UI: data can be dictionary, JSON, entity, etc
//! formdata pointing to view: traverse from uilist to get the form data list of attribute isformui
//! formdata pointing to view: traverse from uilist to get the form data list of attribute isformui  superView :指定一个父,不指定则为根视图


Base classes mainly define the following categories:

1. Common tool class definition:

Stmsgbox, sthttp (these two classes, except Sagit.XXX Call, also in the controller self.XXX Call.)




2. Initialization events: OnInit, oninitui, oninitdata

OnInit and oninitui events are uiview related, because the core simplification mechanism of the framework lies in the causes.

Normally, there are four files in a page:





The SAGIT framework eliminates the first three files and only needs xxcontroller. M.


After simplification, the definition in xxxcontroller. H is written directly into xxxcontroller. M.

The initial function of UI is defined in the controller base class, and UI code can be initialized directly.


When you need to set the status bar, navigation bar and global settings, you can set the insurance in this function. If you set to oninitui, global may not take effect.


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

3. Matching verification of forms: ismatch

Used to verify the type or required of Dictionary:

Example code:


Prompt words:

XXX cannot be empty.

XXX format error.

The final prompt: the mobile phone number cannot be empty and the format of the mobile number is wrong.


4. Form batch value submission: formdata

For some personal data to fill in, you can submit them in batch to save one value.

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. It is a dictionary.

You can add other parameters, such as longitude and latitude, which are not presented in the form.

5. Automatic batch assignment of forms: settoall

Or the interface above:

Restore loaded code example:



There are three kinds of settoall receiving parameters:

1. JSON string

2. Dictionary

3. Entity class inherited from stmodelbase

6. Field value and assignment of single UI: stvalue

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


Other: core loading reason:

    //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 is handled in loadview in viewcontroller. The default value is self.view It's stview
        self.view=self .stView=[[STView alloc] initWithC ontroller:self ]; // change view to stview
    [self initUI];

When the xxxcontroller is initialized:

1. It will first find a class that has no xxxview, and if so, initialize it to its own default view.

2. If not, create an empty view as your default view.

This is the end of this article.

Recommended Today

Summary of recent use of gin

Recently, a new project is developed by using gin. Some problems are encountered in the process. To sum up, as a note, I hope it can help you. Cross domain problems Middleware: func Cors() gin.HandlerFunc { return func(c *gin.Context) { //Here you can use * or the domain name you specify c.Header(“Access-Control-Allow-Origin”, “*”) //Allow header […]