UITablewViewController显示黑屏

时间:2018-03-17 17:43:05

标签: swift uitableview uinavigationcontroller uitabbarcontroller

我为此搜索了StackOverflow,但没有一个答案可以帮助我。

我有一个带有以下代码的UITablewViewController:

class MessagesViewController: UITableViewController
{

    lazy var activeChats = [PrivateChatUITableViewCell]()

    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.view.layer.backgroundColor = UIColor.white.cgColor
        self.tableView.backgroundView = nil
        self.tableView.backgroundColor = UIColor.white

        self.view.addSubview(self.tableView)


    }

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

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

        let cell = UITableViewCell( style: UITableViewCellStyle.default, reuseIdentifier: "chat_room_cell" ) as! PrivateChatUITableViewCell
        let currentUserID = Constants.refs.currentUserInformation?.uid
        let query = Constants.refs.databaseChatsLite.child(currentUserID!)

        _ = query.observe(.childAdded, with: { [weak self] snapshot in

            if  let data        = snapshot.value as? [String: String],
                let contactName        = data["userName"],
                let newMsgs        = data["newMessage"],
                let contactImg = data["userImageStr"]
            {
                let contactID = snapshot.key

                //cell.ContactImageView = UIImageView.loadImageUsingUrlString(contactImg)
                cell.ContactName.text = contactName
                cell.NewNotificationsNum.text = newMsgs
                cell.ContactID = contactID
            }
        })



        return cell

    }

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

        chatToLoad = activeChats[indexPath.row]
        performSegue(withIdentifier: "segue_to_chatroom", sender: self)
    }

    var chatToLoad: PrivateChatUITableViewCell? = nil

    override func prepare(for segue: UIStoryboardSegue, sender: Any?)
    {
        if (segue.identifier == "segue_to_chatroom")
        {
            let destination = segue.destination as! PrivateChatViewController
            destination.senderId = Constants.refs.currentUserInformation?.uid
            destination.senderDisplayName = Constants.refs.currentUserInformation?.displayName
            destination.contactID = chatToLoad!.ContactID

        }
    }

}

位于TabViewController。当我单击该选项卡时,视图全部为黑色。我尝试使用self.view.layer.backgroundColor = UIColor.white将其设置为白色(正如您在ViewDidLoad方法中看到的那样),但这没有帮助。我试图手动将颜色设置为白色然后默认,但这也没有帮助。

TabBar连接到NavigationController,以模态方式显示UIView

我的故事板图片:

Storyboard snapshot

The Black Screen

如何将背景颜色设为白色?

0 个答案:

没有答案