Storyboard creating a controller 1. Load the storyboard file first (test is the file name of storyboard)
Uistoryboard *storyboard = [Uistoryboard storyboardwithname:@ "Test" Bundle:nil];
2. Then initialize the controller in the storyboard
Initialize the "Initial controller" (the controller that the Arrow refers to)
Mjviewcontroller *MJ = [Storyboard Instantiateinitialviewcontroller];
Initialize the corresponding controller with an identity
Mjviewcontroller *MJ = [Storyboard instantiateviewcontrollerwithidentifier:@ "MJ"];
Complete method:
Uistoryboard *story=[uistoryboard storyboardwithname:@ "njwisdomcard" Bundle:nil]; Njwisdomcarddetailviewcontroller *wisdom=[story instantiateviewcontrollerwithidentifier:@ " Njwisdomcarddetailviewcontroller " ]; Wisdom.bindaliascode=cardId; wisdom.hidesbottombarwhenpushed=YES; [Self.navigationcontroller pushviewcontroller:wisdom Animated:yes];
Segue what is the Seguestoryboard on each of the lines used to interface jump, is a Uistoryboardsegue object (Segue) Segue properties
Each of the Segue objects has 3 properties
1. Unique identification
@property (nonatomic, readonly) NSString *identifier;
2. SOURCE Controller
@property (nonatomic, readonly) ID Sourceviewcontroller;
3. Target Controller
@property (nonatomic, readonly) ID Destinationviewcontroller;
The type of segue according to the Segue execution (jump) moment, segue can be divided into 2 major types
- Auto-type: After clicking on a control (such as a button), automatic execution of Segue, auto-complete interface jump
- Manual type: Need to write code to manually perform segue to complete the interface jump
Automatic TypeControl-Drag the line directly from the control to the target controller click on the "Login" button, will automatically jump to the right controllerManual Type1. Hold down the control key and drag the line from the source controller to the target controller 2. Manual type segue need to set an identity (check the arrow settings) 3. At the right moment, use the Perform method to perform the corresponding segue
[Self Performseguewithidentifier:@ "login2contacts" Sender:nil];
Usage Recommendations
- After clicking on a control, do not need to make any judgment, be sure to jump to the next interface, it is recommended to use "Automatic type Segue"
- After you click on a control, you need to make some judgments, that is to say: to meet certain conditions before jumping to the next interface, it is recommended to use "manual type Segue"
Examples of Use
Click to login, to determine the jump (manual type)
/** * Login*/-(ibaction) Login {if(! [Self.accountField.text isequaltostring:@"MJ"]) { //account does not exist[Mbprogresshud ShowError:@"account does not exist"]; return; } if(! [Self.pwdField.text isequaltostring:@"123"]) { //Password Error[Mbprogresshud ShowError:@"Password Error"]; return; } //Show A mask (cloak)[Mbprogresshud ShowMessage:@"Brother is helping you log in ...."]; //send a network request//Simulation (1 seconds to execute jump)Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (1.0* nsec_per_sec)), Dispatch_get_main_queue (), ^{ //Remove Cover[Mbprogresshud Hidehud]; //Jump--Execute login2contacts this segue[Self Performseguewithidentifier:@"login2contacts"Sender:nil]; });}/** * After executing the segue, this method will be called before the jump * usually here to pass the data to the next controller*/- (void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender{//1. Get the target controller (contact list Controller)Uiviewcontroller *CONTACTVC =Segue.destinationviewcontroller; //2. Setting the titleContactvc.title = [NSString stringWithFormat:@"%@ 's Contact list", Self.accountField.text];}@end
Multiple controller jumps (auto)
/** * will be called before executing a jump * In this method, the target controller's view has not been created yet*/- (void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender{IDVC =Segue.destinationviewcontroller; if([VC Iskindofclass:[mjaddviewcontrollerclass]]) {//If you are jumping to a controller that adds a contact//set up a proxy for the next controller (add a contact's director)Mjaddviewcontroller *ADDVC =VC; ADDVC.Delegate=Self ; } Else if([VC Iskindofclass:[mjeditviewcontrollerclass]]) {//if it is jump to view (edit) The controller of the contactMjeditviewcontroller *EDITVC =VC; //get the line that's selectedNsindexpath *path =[Self.tableview Indexpathforselectedrow]; Editvc.contact=Self.contacts[path.row]; EDITVC.Delegate=Self ; }}
IOS UI Basics -12.0 Storyboard