Most of the previous page jumps on iOS are pressed back to the Xib form, but my humble use is storyboard. This article only introduces the use of storyboard for page jump and pass value.
New Page
The iOS program also uses the idea of MVC, where the paging file is separated from the code file, which is similar to Android. In the way of using storyboard, the new page only needs to be dragged into a view controller in storyboard.
You can then add a variety of controls to the newly created page to edit the newly created page.
Orchestrating the various view controls on a new page is like editing the XML for that layout in Android, but there are some things you need to do to get the program code to associate with this view. First of all it is necessary to create an associated class, at this time need to create a new Objective-c class, the base class to select the corresponding view controller base class, here is the simplest uiviewcontroller,with XIB for the user Interface that check box is not tick, click Done to successfully create a view Controller.
Go back to the Stroyboard view, select the newly created view page, click on the Red box section
Select the corresponding view controller in the red box so that the view is associated with the program code file View Controller.
Page Jump
After creating a new page, you can jump between pages, and the simplest jump is to use a similar build control outlet or binding event, hold down the CTRL key and drag to the page you want to jump to, then select Modal in the popup window:
Click the button after running the program to achieve the jump.
Another way to jump is to press the CTRL key on the start page and then drag to the target page, the pop-up window option is the same as above, and then select two page lines, the red box to the segue named:
Finally, add the following code where the view controller wants to trigger a jump (for example, by clicking the button, in the method of the button's Click event)
| 1 |
[self performSegueWithIdentifier:@“segue的名” sender:nil]; |
You can implement jumps.
To return to the previous page after jumping to a new page, add the following code where you need to return
| 1 |
[self dismissModalViewControllerAnimated:true]; |
The parameter true and false represent whether animations are used when switching the page to jump
Inter-page Value transfer
The simplest way to pass values between pages is to define a global variable, whether it is a jump or a return, from which you can get/set to a value, and if you do not use this method, the Prepareforsegue sender method can be used to return the value, and the way the protocol can be used when returning. Let's look at the following separately.
Using the Prepareforsegue sender method to pass a value, you need to first declare the properties of the passed parameter at the class declaration of the target page's view controller, for example, that property is called Value1 Bar, and then in the Start page where the method is implemented
| 123456 |
-(void) prepareforsegue: (uistoryboardsegue *) segue sender: (ID) {    &NBSP, if ([segue.identifier compare:@ "Mysegue" ]==no)      { id page2=segue.destinationviewcontroller;          [page2 setvalue:self.lbusername2.text forkey:@ "Value1"      } } |
As a function of SetValue Forkey, Segue's Destinationviewcontroller can obtain the view Controller of the target page to which the current segue jumps. Here is a decision to determine whether the segue of the jump action is the one that needs to pass the value, because if a page will have more than one segue jump to a different page, do not differentiate, in the target page in the view controller does not have the corresponding parameters will throw an exception.
Using the protocol to return the value of the method, the idea is to define the relevant protocol, the Protocol is to start the implementation of the page, the purpose is to open up some methods for assignment to the target page call, the target page when returning to call those methods to return the value back to the Start page, the target page how to get the Start Page instance, Then pass the value through the SetValue Forkey method on the page, and here is an example
Defining protocols
| 12345 |
@protocol HGReturnView1Delegate <nsobject>-(void) setReturnText:(NSString *) value;@end</nsobject> |
The start page needs to implement the Protocol, and the implementation part of the code is not posted. At the declaration of the target page, you need to define one of the above protocol properties:
| 1 |
@property (weak,nonatomic) id delegate; |
The following code is called when the page jumps:
| 1 |
[self setValue:self forKey:@”delegate”]; |
The delegate property needs to be cast on return, and the Setreturntext method is called after the conversion.
| 12 |
NSObject[tmpDele setReturnText: self.txtReturn.text]; |
Here, the value of the page is completed.
From:cocoschina
iOS use Stroryboard page jump and pass value