【发布时间】:2015-07-21 12:38:44
【问题描述】:
我正在尝试使用带有多个 key-value 对的 dictionary 创建一个类似字典的应用程序。
这个想法是当用户在textField 中键入和现有key 并单击button 时,key 上的value 会显示在label 上。我只能在单击button 时显示所有条目(包括键和值)(无论textField 的内容如何),但这不是我想要实现的目标。
这是我的代码:
//
// ViewController.swift
// Dictionary
//
// Created by Ralph on 7/20/15.
// Copyright (c) 2015 Ralph. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
let words = [
“doe” : “a deer, a female deer”,
“ray" : “a drop of golden sun”,
“me” : “a name I call myself”
]
@IBOutlet weak var textField: UITextField!
@IBAction func searchButton(sender: AnyObject) {
displayMeaning.text = words.description
}
@IBOutlet weak var displayMeaning: UILabel!
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.
}
}
【问题讨论】:
-
我没有看到您正在检索文本字段中输入的键的值。
标签: ios swift uibutton uitextfield uilabel