I'm having trouble with the TableView I added into my ViewController. 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. 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.
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. @nivritgupta was right. Thanks!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.