When it comes to storyboard, we have repeatedly emphasized that storyboard solves the problem of jumping between pages. A rather complex page jump, once the use of storyboard, will be four or two to dial the Jack. You can do a jump between uiviewcontroller simply by dragging it. There is an artifact, an extremely important method, which is: Prepareforsegue:sender:
From the simple expression of method, it can be seen at a glance that it has 2 parameters (arguments). Why, because he has 2 colons. In fact, the complete expression of this method is:-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender
The first parameter is segue, and the second parameter is sender.
Here is an example of a code that shows a common approach to this method. This code is written in the. m file that corresponds to the current viewcontroller.
This method mainly solves 2 problems:
(1) Get the View controller (Viewcontroller) to which you want to jump;
(2) At the same time, the data from the previous view is passed to the next view. (For example: The previous view is TableView, then the row number of the Click cell is passed to the next view).
Uiviewcontroller *destination = Segue.destinationviewcontroller; As long as it is prepareforsegue:sender: always declare a target view controller (destination Viewcontroller);
Once you get to the next view controller, you can jump past it. But just jump is not enough, you have to pass the data past it. For example, the previous view is TableView, and when a user clicks on a cell to enter the next page, the cell line number that is clicked is passed to the next page.
There is a flexible delivery method that passes values by following KVC (key-value-coding) rules. Specifically, the data is stored by [Viewcontroller Setvalue:forkey:]. Since the storage method is provided, there is a corresponding way to get it. In technical terms, that is: Read and write operations are in pairs appear. If you have a sale, you have to buy it. Oh
The previous writing is the cushion, next, we focus on the next Prepareforsegue:sender: the use of. The trigger condition for this method is:
Specifically for TableView, when a cell is clicked, the corresponding segue of that cell will be activated and the method will be called. The data transmission problem that we care about most is taking advantage of this time.
Before the advent of Stroyboard technology, the transfer of data will be achieved through TableView delegate, which is somewhat troublesome. As you can see, with storyboard technology, technology is so simple. Of course, you can also go to the next page by clicking the button. In any case, the jump to the view can easily be achieved with segue.
Looking back, let's take a closer look at this prepareforsegue:sender: this magical method.
In order to distinguish the jump of a view, it can be represented by the previous, next, or by the source view and the target view. namely: Sourceviewcontroller and Destinationviewcontroller. The target view controller is the view that is about to be displayed (loaded), and the Source view controller refers to the view controller that is about to be superseded.
Writing here, I feel a little lazy. Segue, while implementing a jump between views, is actually a switch between view controllers. Rather, segue implements a jump between the Secene (scene).
"Turn" Storyboard's Prepareforsegue:sender: