2015-10-27 162 views
-1

我有一个文本框和一个按钮。 当用户在我的文本框中输入一个数字并点击按钮时,我的程序将打印一个句子。我可以在Xcode中看到我的打印内容,但它本身并不出现在应用程序屏幕上。输入和输出

需要哪些代码才能在应用程序本身显示我的打印内容,而不仅仅是Xcode的“输出部分”。

+0

关注标签上的教程:https://www.youtube .com/watch?v = 5ETjo1PaQbI – Kametrixom

+0

视频并不能帮助我,因为我仍然需要知道需要使用哪种代码才能将我的“if”句子与我的印刷品连接到标签。 – Frederic

+0

向我们显示您的代码。我们不知道你的“如果句子”是什么样子。堆栈溢出是为了帮助解决代码问题,而不是为你写代码或给出建议...... – Grimxn

回答

0

它`看起来像你的前一个问题的延续:Swifit (my first program) catching user input

在这种情况下,你需要做的财产以后这样的:

class ValuesChecker { 

    class func checkValues(firstValue: Float, secondValue: Float) -> String { 
     if firstValue < 99.5 { 
      return "you need more attempts :(Shoot some more!!" 
     } else if firstValue > 99 && secondValue > 49 && secondValue/firstValue > 0.4999 { 
      return "accepted" 
     } else { 
      return "failed " 
     } 
    } 
} 

class ViewController: UIViewController { 

    // Add this outlet and make connection from storyboard 
    @IBOutlet weak var label: UILabel! 
    @IBOutlet weak var firstTextField: UITextField! 
    @IBOutlet weak var secondTextField: UITextField! 

    @IBAction func actionWithPressButton(sender: AnyObject) { 
     let firstValue = (firstTextField.text as NSString).floatValue 
     let secondValue = (secondTextField.text as NSString).floatValue 

     // text to your label 
     label.text = ValuesChecker.checkValues(firstValue, secondValue: secondValue) 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 
}