在swift中将字符串格式化为NSString

时间:2015-04-14 21:05:28

标签: ios swift

我试图将tableViewCell属性设置为不同的标签。但是我一直在收到有关字符串的错误。我已经开始像这样挂起阵列了。

 cell.titleViewLabel.text = arrayNews[indexPath.row].title

但是我不断收到此错误

cannot assign a value of type nsstring to a value of type string

如何将上述标题格式化为NSString,以便在cellForRowAtIndexPath中不会出现此错误?或者这是由于其他原因?

1 个答案:

答案 0 :(得分:1)

<强>问题:

问题的根源如下:

cell.titleViewLabel.textNSString

arrayNews[indexPath.row].titlestring

<强>解决方案:

您需要将string强制转换为NSString。请尝试以下语法

cell.titleViewLabel.text = arrayNews[indexPath.row].title as NSString