ios - 自定义 UITableViewCell 异常

标签 ios uitableview

它可以是什么? 无法在 (UIView) 上设置(标识符)用户定义的检查属性:[setValue:forUndefinedKey:]:此类对于键标识符不符合键值编码。 在 iOS 8 上它可以工作,但在调试器中发送垃圾邮件,在以前的版本中它会崩溃应用程序。 我检查并重新连接了界面生成器中的所有连接。

我的代码 cellForRowAtIndexPath:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCellWithIdentifier(self.identifier, forIndexPath: indexPath) as PostCell

        cell.backgroundColor = UIColor.clearColor()

        cell.likeButton.setBackgroundImage(UIImage(named: "post_like_active"), forState: UIControlState.Selected)
        cell.dislikeButton.setBackgroundImage(UIImage(named: "post_dislike_active"), forState: UIControlState.Selected)

        var storageManager: PostStorageManager = PostStorageManager.sharedManager()
        var model: PostModel = storageManager.storageObjects()[indexPath.row] as PostModel

        cell.likeButton.selected = model.likeManager.likeState!.liked
        cell.dislikeButton.selected = model.likeManager.likeState!.disliked

        cell.textView.text = model.text
        cell.textView.font = UIFont(name: "HelveticaNeue-Light", size: fontSize)!
        cell.textView.contentInset = UIEdgeInsets(top: self.contentInsetTop, left: 0, bottom: 0, right: 0)

        cell.likeLabel.text = String(format: "%@", model.amountOfLikes)
        cell.dislikeLabel.text = String(format: "%@", model.amountOfDislikes)

        var date: NSDate = model.date

        cell.timeLabel.text = date.timeAgo()

        var tapRecog: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tapOccure:")
        tapRecog.numberOfTapsRequired = 1
        cell.textView.addGestureRecognizer(tapRecog)

        var isMan = model.isMan.boolValue

        cell.trollfaceImage.image = UIImage(named: String(format: "%@_%i", isMan ? "man" : "woman", model.experiance.integerValue))

        var manColor = UIColor(red: 41/255, green: 86/255, blue: 115/255, alpha: 1)
        var womanColor = UIColor(red: 206/255, green: 68/255, blue: 96/255, alpha: 1)
        cell.ageLabel.textColor = isMan ? manColor : womanColor
        cell.ageLabel.text = String(format: "%i", model.age.integerValue)

        cell.textView.userInteractionEnabled = false

        return cell
    }

最佳答案

检查单元格中的所有 View ,我认为您将标识符放在错误的位置。

关于ios - 自定义 UITableViewCell 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27346576/

相关文章:

ios - 在 UIView 上绘制点和线

ios - 如何在 UITableView 或 UICollectionView 上实现类似滚动行为的 Peek Calendar?

ios - 类型 'GTLDriveFile' 的值没有成员 'downloadUrl'

ios - 使用结构从 TableViewController 更改 tableViewCell

objective-c - 无法将 UIImage 项目添加到 NSMutableArray - EXC_BAD_ACCESS 错误

ios - reloadRowsAtIndexPaths 时崩溃 'Could not load NIB in bundle '

ios - 测试 UITableViewCell 是否已被删除

ios13 防止下拉滚动到顶部的 tableView 以消除以模态呈现的 viewController 的工作表样式

ios - 动画 subview

ios - Xcode Storyboard 警告 : Constraint referencing items turned off in current configuration. 在当前配置中关闭此约束