希望老师讲讲MVC的分离和语言访问的权限控制
//
// ViewController.swift
// ChineseZodiac
//
// Created by 赵津 on 15/7/13.
// Copyright (c) 2015年 Play Interactive. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//重写screen的touch end事件(用户点击屏幕的任何地方,结束touch之后都会被执行),解决用户不做查询时,不会自动收起的问题
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
yearOfBirth.resignFirstResponder()
}
@IBOutlet weak var yearOfBirth: UITextField!
@IBOutlet weak var shuxiangImg: UIImageView!
@IBOutlet weak var yearOfShuXiang: UILabel!
@IBAction func confirmTapped() {
//让输入控件失去焦点,解决查询结束之后键盘不会自动收起的问题
// yearOfBirth.resignFirstResponder()
if let birthYear = yearOfBirth.text.toInt(){
let seachResult = parseYearGetShuXiangInfo(seachYear: birthYear)
shuxiangImg.image = UIImage(named: String(seachResult.imgNumb))
yearOfShuXiang.text = seachResult.shuXiangTxt
}else{
println("用户没有输入年份信息!")
}
}
private func parseYearGetShuXiangInfo(seachYear year: Int) ->(imgNumb: Int,shuXiangTxt: String){
//位移:08是鼠年 % 12个生肖
var imgReflectArr = ["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]
var baseYear = 2008
var shengXiaoCount = imgReflectArr.count
var offset = baseYear % shengXiaoCount
var shuXiangImgNumb = (year - offset) % shengXiaoCount
var shuXiangTxt = imgReflectArr[(year - offset) % shengXiaoCount]
return (shuXiangImgNumb, shuXiangTxt)
}
}