试。
我的小项目有问题。
它会运行,但如果我尝试向下滚动它会崩溃!
带有致命错误的代码部分是:
func fontForDisplay(atIndexPath indexPath: NSIndexPath) -> UIFont? {
if indexPath.section == 0 {
let familyName = familyNames[indexPath.row]
let fontName = UIFont.fontNamesForFamilyName(familyName).first! as String
return UIFont(name: fontName, size: cellPointSize)
} else {
return nil
}
}
你能帮助我吗?
谢谢!
答案 0 :(得分:0)
我猜投降失败,如果让
包裹它if let fontName = UIFont.fontNamesForFamilyName(familyName).first as? String{
return UIFont(name: fontName, size: cellPointSize)
}
答案 1 :(得分:0)
let fontName = UIFont.fontNamesForFamilyName(familyName).first
as String! 或
let fontName : String! = UIFont.fontNamesForFamilyName(familyName).first