Swift&;如果Else运行且未停止,则Xcode 6函数
我慢慢地对斯威夫特产生了兴趣 不是最难的,但从我的逻辑角度来看,仍然给我带来了流量问题 我有一个比较Swift&;如果Else运行且未停止,则Xcode 6函数,xcode,swift,if-statement,Xcode,Swift,If Statement,我慢慢地对斯威夫特产生了兴趣 不是最难的,但从我的逻辑角度来看,仍然给我带来了流量问题 我有一个比较textField是否为空的函数 如果为空,则会触发窗口警报,并调用一个函数来设置文本字段抖动的动画,并抛出警报屏幕。我终于让它工作了,但是现在当IF语句在没有弹出警报屏幕的情况下运行时,代码不会在IF语句处停止,而是运行整个代码 我试图让代码在IF部分调用函数,并在else部分调用prepareforsegue 这是当前的工作代码: 以下是我试图实现的目标,但无法正常运行 知道当警报窗口不在时i
textField
是否为空的函数
如果为空,则会触发窗口警报,并调用一个函数来设置文本字段抖动的动画,并抛出警报屏幕。我终于让它工作了,但是现在当IF语句在没有弹出警报屏幕的情况下运行时,代码不会在IF语句处停止,而是运行整个代码
我试图让代码在IF部分调用函数,并在else部分调用prepareforsegue
这是当前的工作代码:
以下是我试图实现的目标,但无法正常运行
知道当警报窗口不在时if语句失败的原因吗?这是设置断点时的样子
你好,乔。只是一些想法。我相信你在这方面比我领先,你在if-then/else块中定义了一个覆盖func。if语句中定义的变量(可能还有函数)的作用域是if语句,也就是说,if语句之外的代码不会识别它们。我看到你定义了这个函数,但没有看到你调用它。此外,我从未在if语句中定义过函数。我不知道这将如何工作。我认为该函数是用“alert()”代码调用的。我是新手,所以我不知道斯威夫特在某些事情上做了什么。谢谢为了好玩,在override函数中放置一个断点,看看它是否被调用。我如何编写断点?对不起,我是个新手,萝莉已经贴出了一张设定断点的照片。要设置断点,请在垂直条上单击鼠标左键。要删除断点,请右键单击该断点,然后选择“删除断点”。您的代码将在此时停止执行,并在此时提供有关程序状态的信息。要从该点继续运行程序,请从主菜单中选择Debug并继续。
func alert() {
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.1
animation.repeatCount = 4
animation.autoreverses = true
animation.fromValue = NSValue(CGPoint: CGPointMake(numOfGuestsData.center.x - 15, numOfGuestsData.center.y))
animation.toValue = NSValue(CGPoint: CGPointMake(numOfGuestsData.center.x + 15, numOfGuestsData.center.y))
numOfGuestsData.layer.addAnimation(animation, forKey: "position")
}
@IBAction func checkText(sender: UIButton) {
if self.numOfGuestsData.text == "" {
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
alert()
let alertController = UIAlertController(title: "Split The Bill", message:
"Please Enter The Number of Guests!", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Okay", style: UIAlertActionStyle.Default,handler: nil))
presentViewController(alertController, animated: true, completion: nil)
} else {
println("everything is Ok Here")
}
}
func alert() {
let animation = CABasicAnimation(keyPath: "position")
animation.duration = 0.1
animation.repeatCount = 4
animation.autoreverses = true
animation.fromValue = NSValue(CGPoint: CGPointMake(numOfGuestsData.center.x - 15, numOfGuestsData.center.y))
animation.toValue = NSValue(CGPoint: CGPointMake(numOfGuestsData.center.x + 15, numOfGuestsData.center.y))
numOfGuestsData.layer.addAnimation(animation, forKey: "position")
}
@IBAction func checkText(sender: UIButton) {
if self.numOfGuestsData.text == "" {
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
alert()
println("something is wrong here")
} else {
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
let subTotalVC = segue.destinationViewController as subTotalAmountViewController
subTotalVC.numOfGuests = numOfGuestsData.text
}
println("everything is Ok Here")
}
}