簡體   English   中英

找不到類型為'UIAlertController'的初始化程序錯誤

[英]Cannot find an initializer for type 'UIAlertController' ERROR

我對此有些陌生,請幫忙!

這是完整的錯誤:

找不到類型為'UIAlertController'的初始化程序,該初始化程序接受類型為'(title:String,message:(Int),preferredStyle:UIAlertControllerStyle)'的參數列表

這是我的代碼中發生錯誤的部分:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate, UITextViewDelegate{

@IBOutlet weak var CalcButton: UIButton!
@IBOutlet weak var DaysLabel: UITextView!
@IBOutlet weak var RateLabel: UITextView!
@IBOutlet weak var CowsLabel: UITextView!
@IBOutlet weak var PoundsLabel: UITextView!

@IBOutlet weak var PoundsTextfield: UITextField!
@IBOutlet weak var CowsTextfield: UITextField!
@IBOutlet weak var DaysTextfield: UITextField!
@IBOutlet weak var RateTextfield: UITextField!
@IBOutlet weak var Label: UILabel!

@IBAction func buttonCalc(sender: AnyObject) {
    var Days: Int = DaysTextfield.text.toInt()!
    var Pounds: Int = PoundsTextfield.text.toInt()!
    var Cows: Int = CowsTextfield.text.toInt()!
    var Rate: Int = RateTextfield.text.toInt()!

    if Days > 0 && Pounds > 0 && Cows > 0 && Rate > 0 {
        Label.text = String(stringInterpolationSegment: Days)
        var sDays = String(Days)
        var sCows = String(Cows)
        let alertController = UIAlertController(title: "Based on the values you entered, this is what the bonus is for \(sCows) cows and \(sDays):", message:
            (Rate/100 * Pounds) * (Cows * Days), preferredStyle: UIAlertControllerStyle.Alert)
        alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))

        self.presentViewController(alertController, animated: true, completion: nil)
    }  
}

@IBAction func NDHIALink(sender: AnyObject) {
   UIApplication.sharedApplication().openURL(NSURL(string: "http://www.dhia.org/")!)
}

謝謝您的幫助

UIAlertController(title: "Based on the values you entered, this is what the bonus is for \(sCows) cows and \(sDays):", message:
            (Rate/100 * Pounds) * (Cows * Days), preferredStyle: UIAlertControllerStyle.Alert)

只需將(Rate/100 * Pounds) * (Cows * Days )轉換為String

UIAlertController(title: "Based on the values you entered, this is what the bonus is for \(sCows) cows and \(sDays):", message:
                String((Rate/100 * Pounds) * (Cows * Days)), preferredStyle: UIAlertControllerStyle.Alert)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM