0
10 개 커피 포인트가 누적 된 후에 (각 커피는 2 포인트가되는) 커피 앱이 있습니다. 무료 커피가 제공됩니다.버튼 및 경고 메시지에 최대 값을 지정하는 방법
최대 커피를 10 개 주문하려면 어떻게해야합니까? 10 점에 도달하면 경고 메시지가 튀어 나오게하십시오.
주문보기의보기 컨트롤러입니다. 어떤 커피가 주문되어 있지 않은 경우 오류 메시지가 발생합니다,하지만 난 사용자가 경고 메시지를 확인하려면 10 점
import Foundation
import UIKit
class OrderingViewController: UIViewController {
var cstudent: Student = Student("name", "000")
var totalNumberOfCoffees = 0
var maximumNumberOfCoffee = 10
let minimumB = 0
let maximumA = 10
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func cappaPressed(_ sender: Any) {
totalNumberOfCoffees += 2
}
@IBAction func flatwhitePressed(_ sender: Any) {
totalNumberOfCoffees += 2
}
@IBAction func mochaPressed(_ sender: Any) {
totalNumberOfCoffees += 2
}
@IBAction func esspresso(_ sender: Any) {
totalNumberOfCoffees += 2
}
@IBAction func placeOrderPressed(_ sender: Any) {
// by using this function, it makes the user know that they must order at least one
// coffee. if this were not here, it could waste the user's time as they
// may not be aware or may have made a mistake by not clicking on a coffee button.
if totalNumberOfCoffees > 0 { // you cannot order 0 coffees
performSegue(withIdentifier: "placeOrderSegue", sender: self)
}
displayAlertMessage(userMessage: "You cannot order no coffees!")
if minimumB >= maximumA {
totalNumberOfCoffees = maximumNumberOfCoffee
}
displayAlertMessage(userMessage: "FREE COFFEE")
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "placeOrderSegue"){
let datasend = segue.destination as! AccountViewController
datasend.currentstudent = cstudent
// this passes the name of the student logged in, back to the
// AccountViewController. This is useful as if it were not here, the
// name of the user would be lost.
datasend.currentstudent.numOfCoffees += totalNumberOfCoffees
// add coffees bought to current student. this makes the
// student logged in know how many coffees they're oreder.
}
}
// alert message.
func displayAlertMessage (userMessage: String) {
let myAlert = UIAlertController(title: "Nothing has been ordered", message:userMessage, preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "ok", style: UIAlertActionStyle.default, handler: nil)
//the okAction is the button which is pressed by the users which lets them re-order on
// the same view controller (orderingViewController)
myAlert.addAction(okAction)
self.present(myAlert, animated: true, completion: nil)
}
}
에 위 또는 같은지 여부를 확인이 필요하기 checkReach의 FUNC를 만들 수 있을까? –
또한 게시하기 전에 코드 형식을 미리 보시기 바랍니다 –
totalNumberOfCoffees는 포인트를 저장하는 var입니다. @PakHoCheung –