NSString变量到Swift上的UITextField文本

时间:2014-08-20 08:15:53

标签: ios nsstring swift uitextfield

我需要从NSMutableDictionary中获取NSString并将其分配给UITextField的文本。

但我得到了例外;在展开可选值时意外发现nil

当我记录它写入控制台的字符串时。

我的代码如下;

    let tempString:NSString! = tempDict.objectForKey("name") as? NSString

    NSLog("%@",tempString)

    cell.textLabel.text = tempString  //This line gives the exception

2 个答案:

答案 0 :(得分:1)

通过添加if语句安全地解包cell.textLabel来阻止它。

if var label = cell.textLabel{
    label.text = "This is a title"
}

希望这会有所帮助.. :)

答案 1 :(得分:0)

你可以尝试这个。它有助于摆脱我遇到的同样问题

让userName:NSString = result.valueForKey(" name")为!的NSString                 self.lblUserName.text = userName as String

相关问题