The fleeting, Riyuerusuo, blink of an eye to learn the journey has been more than half, forget their own hit the batch of code, look at their own pay and efforts, silently for their own this few months of struggle feel gratified, no matter how hard the journey of learning, but I still insist on the past, thinking of their own, Seems to have never been so persistent, nor so serious, so the difficult road themselves have come, the latter I believe must be brilliant tomorrow and brilliant future, perhaps some people say that when a programmer really good bitter, but I do not think so, because this is what I want to do, but also I aspire to, Is my choice of the road, do "you" want to achieve our common GOAL!!!!
In this seemingly long and short day, I finally realize the precious time, also know the importance of the time, I hope everyone and I like to cherish the time, grasp the moment around. Today we mainly learn the value of the transfer in Swift, first by the forward value, and then the right after the forward value, of course, there are more than one kind of, the following I would like to briefly introduce in the value of one of the methods we often encounter, hope that we have a harvest of the same time more comments Kazakhstan:
First, storyboard build UI interface steps in detail
One of the steps to create a project here is not much to mention, because in the previous said, of course, do not understand can ask Oh, the following simple message the basic flow of value:
1. But the word steps:
The arrow is the direction of the story is the storyboard, the next step is to drag the control, UI interface to build
The original controller has been deleted, and then re-drag up to a navigationcontroller, of course, the control can be searched, the following is to point out the specific location of the search
Of course, the size will be a little unbearable when you just drag in, but we still have a plan, the following points out
First we need to select the control we dragged up and then check the red circle option, then we can see the rectangle circled out of the area, we click on it, we will pop up the arrow refers to the prompt box, we choose the arrow refers to the option to achieve our needs.
The next step is similar to what is said above is the simple drag control, as far as the size of the tube, because we have at the beginning of the adjustment, the control after the effect of drag, such as:
As for the arrow, there may be some people who don't know that. We need to tune in another option to have the first view as our root View controller:
This simple UI interface is basically done
Second, the code to achieve a specific value-transfer process
First of all we need to build a few classes to let our control according to the implementation of the requirements of separate inheritance, and then we need their own key model layer, for data management, the following for everyone with upload value of the specific code, may not be detailed enough, please also point out.
class Addressbooktableviewcontroller: Uitableviewcontroller { var arry = [Addre Ssbook] () func getData (ntf:nsnotification) {self.arry.append (ntf. ) object as AddressBook)} override Func Viewdidload () {Super.view Didload () Nsnotificationcenter.defaultcenter (). Addobserver (Self, selector:selector ( " getdata: " ), Name: " aaa " , : Nil)
varModel:addressbook =AddressBook ()varDIC = dictionary<string, string>() dic["name"] =Nametextfiled.text dic["Sex"] =Sextextfield.text dic["PhoneNumber"] =phonetextfield.text model.setvaluesforkeyswithdictionary (DIC) Nsnotificationcenter.defa Ultcenter (). Postnotificationname ("AAA",Object: Model, Userinfo:dic)//self.delegate!. Addinfo (model) varalt = Uialertview (title:"Add Success", Message:"name:\ (Nametextfiled.text) sex:\ (Sextextfield.text), phonenumber:\ (Phonetextfield.text) have been inserted",Delegate: Self, Cancelbuttontitle:"OK") alt.show ()
This is a forward-and-backward method of passing values, which is similar to how contacts are added to a contact.
Next, I will introduce you to the previous method, that is, click on the contact person to jump to the details page implementation.
varArry =[AddressBook] ()varModel1:addressbook =AddressBook ()varDIC = dictionary<string, string>() dic["name"] ="Caomin"dic["Sex"] ="Unknown"dic["PhoneNumber"] =" the"model1.setvaluesforkeyswithdictionary (DIC) self.arry.append (MODEL1)
OverrideFunc Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject!) { //Get The new view controller using [Segue Destinationviewcontroller]. //Pass the selected object to the new view controller. ifSender isUITableViewCell {varCell = Sender asUITableViewCellvarIndexpath =Tableview.indexpathforcell (cell)varModel = self.arry[indexpath!. Row]varVC = Segue.destinationviewcontroller asViewcontroller VC.Delegate=Self vc.info=Model}Else { varVC = Segue.destinationviewcontroller asViewcontroller VC.Delegate=Self }} Func Addinfo (Info:addressbook) {self.arry.append (info)}
Of course, this premise is to follow the agent, and then implement the method in the agent, the specific creation of proxy and proxy methods I would like to add the following for everyone.
This is the two simple method of transmission, hope can help everyone to learn swift language faster, if there is nothing to understand although I put forward, there are questions must answer oh, haha.
Well, it's here today, to start reviewing today's knowledge points, good good study, day up! Haha, good study oh Bo friends, we progress together, refueling!
Pass-through values in Swift