swift - cell label.text是可选的

时间:2016-10-04 08:04:48

标签: swift

我的tableViewCell中的每个optional(1)都正确显示,但只有我的attributeString输出为“ let mString = String(self.productList?["market_price"].int) let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: mString) attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, rnge: NSMakeRange(0, attributeString.length)) attributeString.addAttribute(NSStrikethroughColorAttributeName, value: UIColor.lightGrayColor(), range: NSMakeRange(0, attributeString.length)) self.marketPriceLabel.attributedText = attributeString

@Bean(initMethod = "init")
public MainContentPane mainContentPane() {...}

@Bean
public LockScreen lockScreen() {...}

@Bean
public LockScreenLockedController lockScreenLockedController() {...}

@Bean
public UserStateBinder userStateBinder() {...}

@Bean
public SessionHandler sessionHandler() {...}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。

let mInt: Int = (self.productList?["market_price"].int)!
let mString: String = String(mInt)
let attributeString: NSMutableAttributedString =  NSMutableAttributedString(string: mString)
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, rnge: NSMakeRange(0, attributeString.length))
attributeString.addAttribute(NSStrikethroughColorAttributeName, value: UIColor.lightGrayColor(), range: NSMakeRange(0, attributeString.length))
self.marketPriceLabel.attributedText = attributeString