【发布时间】:2014-08-20 08:15:52
【问题描述】:
我需要从 NSMutableDictionary 中获取一个 NSString 并将其分配给 UITextField 的文本。
但我遇到了一个例外;解包 Optional 值时意外发现 nil
当我记录它写入控制台的字符串时。
我的代码如下;
let tempString:NSString! = tempDict.objectForKey("name") as? NSString
NSLog("%@",tempString)
cell.textLabel.text = tempString //This line gives the exception
【问题讨论】:
-
好吧,如果字符串没问题,那么它可能是单元格或 textLabel。你确定那些不是零?您是否忘记在 Interface builder 中连接其中一个?
-
显示您的单元格声明
-
var cell:UITableViewCell! = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell if (cell == nil) { cell = UITableViewCell(style: UITableViewCellStyle.Subtitle,reuseIdentifier:cellIdentifier) }
标签: ios nsstring swift uitextfield