
该程序假设改变F到C并反转.使用Switch,它从on变为off和on,假设是C到f,off是F到c,并在文本字段中输入#underneath.单击提交按钮时,它会在文本字段中显示什么,将其传输到预制算法中,然后将其显示在文本字段中.
我相信转换正确但不会显示实际结果.或者它被转换的方式是错误的.
@IBOutlet weak var buttonClicked: UIButton!
@IBOutlet weak var mySwitch: UISwitch!
@IBOutlet weak var myTextField: UITextField!
@IBOutlet weak var User: UITextField!
func stateChanged(switchState: UISwitch) {
if switchState.on {
myTextField.text = "Convert to Celius"
} else {
myTextField.text = "Convert to Farheniet"
}
}
@IBAction func buttonClicked(sender: UIButton) {
if mySwitch.on {
var a:Double? = Double(User.text!)
a = a! * 9.5 + 32
User.text=String(a)
mySwitch.setOn(false, animated:true)
} else {
var a:Double? = Double(User.text!)
a = a! * 9.5 + 32 …Run Code Online (Sandbox Code Playgroud) 因此,我的应用程序是一个基本的音乐库,当用户点击相册时,视图会切换到参考ID,并且该ID与相册相关,只是给出基本信息,如艺术家和歌曲等等.当我运行应用程序时,根本没有发生任何事情或者应用程序崩溃.
var names=[String]()
var identities = [String]()
var ButtonAudioPlayer = AVAudioPlayer()
override func viewDidLoad(){
names = ["That's The Spirit", "Chocolate Starfish and the Hot Dog Flavored Water", "IOWA"]
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int)-> Int{
return names.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath)-> UITableViewCell{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell")
cell?.textLabel!.text = names [indexPath.row]
return cell!
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewControllerWithIdentifier(vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
Run Code Online (Sandbox Code Playgroud)