ios - Done button of UIPickerView doesn't work -
i'm trying put done button picker view because, when slide choose item uipickerview automatically select slided row, prefer have button done:
@iboutlet var tfprojet: uitextfield! var pvprojetdata = ["-choisir-", "rachat de crédits", "renégociation de crédits"] override func viewdidload() { super.viewdidload() let pickerview = uipickerview() if devicetype.is_iphone_4_or_less { pickerview.frame=cgrectmake(0, 200, view.frame.width, 100) } else if devicetype.is_iphone_5 { pickerview.frame=cgrectmake(0, 200, view.frame.width, 200) } else if devicetype.is_iphone_6 { pickerview.frame=cgrectmake(0, 200, view.frame.width, 200) } else if devicetype.is_iphone_6p { pickerview.frame=cgrectmake(0, 200, view.frame.width, 250) } else if uidevice.currentdevice().userinterfaceidiom == .pad { pickerview.frame=cgrectmake(0, 200, view.frame.width, 300) } // pickerview.backgroundcolor = .whitecolor() pickerview.showsselectionindicator = true pickerview.delegate = self pickerview.datasource = self self.pickerview = pickerview let pickertoolbar = uitoolbar() pickertoolbar.barstyle = uibarstyle.black //you can change style pickertoolbar.translucent = true pickertoolbar.tintcolor = uicolor.whitecolor() // or other colours pickertoolbar.sizetofit() let spacebuttonpicker = uibarbuttonitem(barbuttonsystemitem: uibarbuttonsystemitem.flexiblespace, target: nil, action: nil) let cancelbuttonpicker = uibarbuttonitem(title: "ok", style: uibarbuttonitemstyle.plain, target: self, action: "canceldatepicker:") pickertoolbar.setitems([cancelbuttonpicker, spacebuttonpicker], animated: false) pickertoolbar.userinteractionenabled = true tfdatenaissance.inputaccessoryview = pickertoolbar tfprojet.inputview = pickerview tfprojet.inputaccessoryview = pickertoolbar } func numberofcomponentsinpickerview(pickerview: uipickerview) -> int{ return 1 } func selectrow(row: int, incomponent component: int, animated: bool){ } func updatepicker(){ self.pickerview!.reloadallcomponents() pickerview.selectrow(0, incomponent: 0, animated: false) } func pickerview(pickerview: uipickerview, numberofrowsincomponent component: int) -> int { if tfprojet.isfirstresponder(){ return pvprojetdata.count } return 1 } func pickerview(pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? { if tfprojet.isfirstresponder(){ return pvprojetdata[row] } return "" } func pickerview(pickerview: uipickerview, didselectrow row: int, incomponent component: int) { if tfprojet.isfirstresponder(){ let itemselected = pvprojetdata[row] tfprojet.text = itemselected self.tfprojet.endediting(true) } }
i see button ok, doesn't work, when slide row automatically selected.
Comments
Post a Comment