gpt4 book ai didi

ios - 无法识别的选择器发送到实例日期选择器 - swift

转载 作者:搜寻专家 更新时间:2023-11-01 06:24:32 25 4
gpt4 key购买 nike

模拟器在从选取器中选择日期后崩溃。不知道为什么(菜鸟在这里)

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var datePicker: UIDatePicker!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

datePicker.addTarget(self, action: Selector("dataPickerChanged:"), forControlEvents: UIControlEvents.ValueChanged)
}

func datePickerChanged(datePicker:UIDatePicker){
var dateFormatter = NSDateFormatter()

dateFormatter.dateStyle = NSDateFormatterStyle.ShortStyle
dateFormatter.timeStyle = NSDateFormatterStyle.ShortStyle

var strDate = dateFormatter.stringFromDate(datePicker.date)
dateLabel.text = strDate

}

最佳答案

您的方法称为“datePickerChanged”,但在您的 addTarget 调用中您将其称为“dataPickerChanged”。应该是:

datePicker.addTarget(self, action: Selector("datePickerChanged:"), forControlEvents: UIControlEvents.ValueChanged)

关于ios - 无法识别的选择器发送到实例日期选择器 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25313907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com