简体   繁体   English

TableView覆盖View中的整个屏幕

[英]TableView Covering up whole screen in View

I'm having trouble with the TableView I added into my ViewController. 我在添加到ViewController的TableView遇到了麻烦。 Problem is it is eating up the whole screen being black thus hiding everything else. 问题是它吞噬了整个黑色的屏幕,从而隐藏了其他所有内容。

This is what I wanted but instead I got these 这就是我想要的,但是我得到了这些

This is with constraints Horizontal Center and Top away from nearest neighbor 这是受约束的水平中心和顶部距离最近的邻居

This is without any constraints. 这没有任何限制。 Table and cells are seen but it blocks up everything else. 可以看到表格和单元格,但它阻塞了其他所有内容。

Below is the code for my ViewController. 下面是我的ViewController的代码。 I'd like to know how come the TableView is acting like that and how do I go about fixing it so that I get the result I want in the first picture. 我想知道TableView的行为如何以及如何对其进行修复,以便在第一张图片中获得所需的结果。

class WalletViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet weak var lblWalletAddress: UILabel!
@IBOutlet var tableViewAssets: UITableView!

var balance: [Balance] = []
var wallet = Wallet()

override func viewDidLoad()
{
    super.viewDidLoad()
    self.title = "Wallet Details"

    self.tableViewAssets.delegate = self
    self.tableViewAssets.dataSource = self
}

public func numberOfSections(in tableView: UITableView) -> Int
{
    return 1
}

public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
    return wallet.balance.count
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
    let tableCell = tableView.dequeueReusableCell(withIdentifier: "AssetTableCell")// as! AssetTableViewCell
    let assetTableCell = tableCell as! AssetTableViewCell

    assetTableCell.lblAssetName.text = wallet.balance[indexPath.row].asset
    assetTableCell.lblAssetAmount.text = String(wallet.balance[indexPath.row].amount)

    return assetTableCell
}

I've solved it. 我已经解决了 Apparently it was because somehow default background color was black and I've to use Xcode's Suggested Constraints to make everything work together with the TableView. 显然是因为默认的背景颜色是黑色,我不得不使用Xcode的“建议约束”使所有内容与TableView一起使用。 @nivritgupta was right. @nivritgupta是正确的。 Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM