有没有办法循环"如果"声明使用javascript / jquery,例如
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.collectionView?.setPresenting(true, animated: true, completion: nil)
let delegate = UIApplication.sharedApplication().delegate as! AppDelegate
self.selectedCard = delegate.otherCards[indexPath.row]
self.performSegueWithIdentifier("SegueToView_B", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let identifier = segue.identifier {
if identifier == "SegueToView_B" {
let myOtherCardViewController = segue.destinationViewController as? View_BViewController
myOtherCardViewController!.otherCard = self.selectedCard
myOtherCardViewController!.navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor() // Failed to work!!!
myOtherCardViewController?.navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor() // Failed to work, too!!!
}
}
}
使用上面的代码,它会检查一次,但无论第二个答案是什么,它都不会检查,有没有办法让它重复检查,而不用写10亿次if语句......?
答案 0 :(得分:8)
使用“while”循环。
var name = prompt("What's your name?");
while (name === '') {
name = prompt("Try again");
alert(name);
}