Skip to content

Instantly share code, notes, and snippets.

@kenji272
Created May 9, 2015 13:40
Show Gist options
  • Save kenji272/fd82835a0223a34132e5 to your computer and use it in GitHub Desktop.
Save kenji272/fd82835a0223a34132e5 to your computer and use it in GitHub Desktop.
【課題】Part7 足し算と引き算を行うタブアプリ
import UIKit
class AdditionViewController: UIViewController {
@IBOutlet weak var target1Text: UITextField!
@IBOutlet weak var target2Text: UITextField!
@IBOutlet weak var resultLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func Add(sender: AnyObject) {
let target1 = (self.target1Text.text as NSString).integerValue
let target2 = (self.target2Text.text as NSString).integerValue
// 足し算を行う
self.resultLabel.text = "\(target1 + target2)"
// キーボードを隠す
self.target1Text.resignFirstResponder()
self.target2Text.resignFirstResponder()
}
}
import UIKit
class SubtractionViewController: UIViewController {
@IBOutlet weak var target1Text: UITextField!
@IBOutlet weak var target2Text: UITextField!
@IBOutlet weak var resultLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func subtract(sender: AnyObject) {
let target1 = (self.target1Text.text as NSString).integerValue
let target2 = (self.target2Text.text as NSString).integerValue
// 引き算を行う
self.resultLabel.text = "\(target1 - target2)"
// キーボードを隠す
self.target1Text.resignFirstResponder()
self.target2Text.resignFirstResponder()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment