我正在尝试为不同的标签设置 tableViewCell 属性。但是我不断收到有关字符串的错误。我已经开始像这样连接阵列。
cell.titleViewLabel.text = arrayNews[indexPath.row].title
但是我一直收到这个错误
cannot assign a value of type nsstring to a value of type string
我如何将上面的标题格式化为 NSString,这样我就不会在 cellForRowAtIndexPath 中收到此错误?还是其他原因?
最佳答案
问题:
问题根源如下:
cell.titleViewLabel.text
是 NSString
arrayNews[indexPath.row].title
是 string
解决方案:
您需要将string
转换为NSString
。试试下面的语法
cell.titleViewLabel.text = arrayNews[indexPath.row].title as NSString
关于ios - 快速将字符串格式化为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29637394/