后分散DatePicker。
DatePicker如何在TableView中单击特定单元格。此外,我还需要一个完成按钮,以便在使用
在你的TableViewController:
var chosenNumber = 0
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//set your chosenNumber here based on your the cell that was clicked
chosenNumber = 1
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
let controller = segue.destinationViewController as! ViewController
//the startRow variable in the ViewController with the picker is set to the same value as the chosenNumber
controller.startRow = chosenNumber
}
在你的ViewController中使用picker:
var startRow = 0
override func viewDidLoad() {
//the selected item in the spinner will the value of startRow
spinner.selectRow(startRow, inComponent: 0, animated: false)
}
当按钮被点击时隐藏旋转器:
@IBAction func buttonClicked(sender: UIButton) {
spinner.hidden = true
}