Uipickerview
1 //return button Events2 @IBAction func backbuttonclick ()3 {4Self.navigationcontroller?. Popviewcontrolleranimated (true)5 }6 7var authorsarray:[string]!8var appsarray:[string]!9 Ten One Overridefunc viewdidload () { A super.viewdidload () - -Titlelabel.text =titlestring the - - //Do any additional setup after loading the view. - + //Create a selection controller -var Pickerview:uipickerview = Uipickerview (Frame:cgrectmake (0, $,0,0)) + A //Add to view at Self.view.addSubview (Pickerview) - - //Specify the data source -Pickerview.datasource = Self - - //Specify proxy inPickerview.Delegate= Self - to //Create 2 Arrays +Authorsarray = ["Liu Mingyang","Wang Hongjun","Ninglai"] -Appsarray = ["Rental Reviews","where to run?","Alloff","Ijump"," Sudoku"] the * $ Panax Notoginseng - //Some of the commonly used properties and methods are introduced the + A the + - $ } $ - Overridefunc didreceivememorywarning () { - super.didreceivememorywarning () the //Dispose of any resources the can be recreated. - }Wuyi the - /* Wu //MARK:-Navigation - About //In a storyboard-based application, you'll often want to do a little preparation before navigation $ override func Prepareforsegue (segue:uistoryboardsegue!, sender:anyobject!) { - //Get The new view controller using Segue.destinationviewcontroller. - //Pass The selected object to the new view controller. - } A */ + the - //MARK:-Uipickerviewdatasource $ the //How many columns are returned theFunc Numberofcomponentsinpickerview (Pickerview:uipickerview)Int the { the return 2 - } in the //How many rows are returned for each column theFunc Pickerview (Pickerview:uipickerview, numberofrowsincomponent component:int)Int About { the //The 1th column returns the number of Authorsarray the ifComponent = =0{ the returnAuthorsarray.count + } - //the 2nd Column returns the number of Appsarray the Else ifComponent = =1 {Bayi returnAppsarray.count the } the - return 0 - } the the //MARK:-Uipickerviewdelegate the the //to create a selection controller by using a string - //func Pickerview (Pickerview:uipickerview, Titleforrow row:int, Forcomponent component:int), String! the // { the // //The 1th column returns the value corresponding to the Authorsarray the //if component = = 0{94 //return Authorsarray[row] the // } the // the // //the 2nd column returns the value corresponding to the Appsarray98 //else if component = = 1 { About //return Appsarray[row] - // }101 // 102 //return ""103 // }104 the //Create a selection controller with a picture with view106Func Pickerview (Pickerview:uipickerview, Viewforrow row:int, Forcomponent component:int, ReusingView view:uiview!)-&G TUIView107 {108var View:uiview = UIView (Frame:cgrectmake (0,0, $, +))109 the //Create an image view111var ImageView = Uiimageview (Frame:cgrectmake (0,0, +, +)) theImageview.image = UIImage (named:"Cellimage.png")113 the the //Create a text label thevar Label:uilabel = UILabel (Frame:cgrectmake ( +,0, the, +))117 //The 1th column returns the value corresponding to the Authorsarray118 ifComponent = =0{119Label.text =Authorsarray[row] - }121 122 //the 2nd column returns the value corresponding to the Appsarray123 Else ifComponent = =1 {124Label.text =Appsarray[row] the }126 127 - 129 //Add Image the View.addsubview (ImageView)131 the //Add a text label133 View.addsubview (label)134 135 returnView136 }137 138 139 //Trigger Agent event when option is changed $ func Pickerview (Pickerview:uipickerview, Didselectrow row:int, incomponent component:int)141 {142println"The current selection is the first \ (component) column (row) row")143}
iOS Development--ui Swift article &uipickerview