私のコードが機能しません。どうしてか分かりません。問題は、switchChanged関数のプロパティです。プロパティが空の場合、コードは機能しています。UISwitchを正しく使用するには?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let rect = CGRectMake(130, 100, 0, 0)
let uiSwitch = UISwitch(frame: rect)
uiSwitch.setOn(true, animated: true)
uiSwitch.addTarget(self, action: "switchChanged", forControlEvents: UIControlEvents.ValueChanged)
self.view.addSubview(uiSwitch)
}
func switchChanged(uiSwitch: UISwitch) {
var message = "Turn on the switch"
if uiSwitch.on {
message = "Turn off the switch"
} else {
message = "Turn on the switch"
}
let alert = UIAlertController(title: "Information", message: message, preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
}
エラー:「libcの++ abi.dylib:タイプNSExceptionのキャッチされない例外で終了する」
あなたはすでにSwiftをタグに使用していることを示していますが、タイトルに追加する必要はありません。 –