来自Xib的UITableViewCell,单元格高度和单元格选择区域

时间:2018-04-05 13:06:57

标签: ios swift uitableview custom-cell

我有一个UITableViewController,它有一个自定义单元格,我想显示图像和标签。截图可以很好地解释我的问题,看起来像这样

enter image description here

当我选择任何单元格时,它看起来像

enter image description here

在tableviewcontroller中,根据约束,单元格在正确的形状中不可见 这是我的自定义单元格,具有自动布局限制 enter image description here

我如何解决这个问题? ...我在不使用storyboard的情况下以编程方式创建了这个tableviewcontroller。 这是数据源的代码示例和tableviewcontroller的委托

override func numberOfSections(in tableView: UITableView) -> Int {
    var numOfSections: Int = 0
    let count = conversations.count
    if count > 0 {
        //  tableView.separatorStyle     = .none
        numOfSections                = 1
        tableView.backgroundView = nil
    }
    else
    {
        let frame                   = CGRect(x: 0,
                                             y: 0,
                                             width: tableView.bounds.size.width,
                                             height: tableView.bounds.size.height)
        let noDataLabel: UILabel    = UILabel(frame: frame)
        noDataLabel.text            = "You don't have any messages. "
        noDataLabel.textColor       = UIColor.black
        noDataLabel.textAlignment   = .center
        tableView.backgroundView    = noDataLabel
        tableView.separatorStyle    = .none
    }
    return numOfSections
}




override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return conversations.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "inboxCell", for: indexPath) as! InboxCell

    cell.conversation = conversations[indexPath.row]

    return cell


}



override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    let uids = conversations[indexPath.row].conversationUseruids
    for uid in uids{

        if uid == Account.account.user.uid{

        }
        else{

            User.getUser(with: uid, completion: { (user) in
                self.selectedUser.append(user!)
            })
        }


    }

    tableView.deselectRow(at: indexPath, animated: true)

    let index = indexPath.row as Int
    messageVC.conversationIndex = index
    messageVC.conversation = self.conversations[index]


    navigationController?.pushViewController(messageVC, animated: true)


}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    return 80
}

1 个答案:

答案 0 :(得分:0)

发生这种情况是因为如果没有工作,你的图像没有上限约束而不是让我知道