我在使用添加到 ViewController 中的 TableView 时遇到了问题。问题是它吞噬了整个屏幕,从而隐藏了其他所有内容。
这就是我想要的,但我得到了这些
这是有水平中心和顶部距最近邻居的约束
这没有任何限制。可以看到表格和单元格,但它挡住了其他所有内容。
下面是我的 ViewController 的代码。我想知道 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
}
最佳答案
我已经解决了。显然这是因为默认背景颜色是黑色,我必须使用 Xcode 的建议约束来使所有内容与 TableView 一起工作。 @nivritgupta 是对的。 谢谢!
关于ios - TableView在View中覆盖整个屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50935447/