我需要从 NSMutableDictionary 中获取一个 NSString 并将其分配给 UITextField 的文本。
但是我得到了一个异常(exception);在展开可选值时意外发现 nil
当我记录它写入控制台的字符串时。
我的代码如下;
let tempString:NSString! = tempDict.objectForKey("name") as? NSString
NSLog("%@",tempString)
cell.textLabel.text = tempString //This line gives the exception
最佳答案
您可以通过添加 if 语句安全地展开 cell.textLabel 来阻止它。
if var label = cell.textLabel{
label.text = "This is a title"
}
希望这会有所帮助..:)
关于ios - Swift 上 UITextField 文本的 NSString 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25399856/