【问题标题】:UITableView is not appearing in iPhoneUITableView 没有出现在 iPhone 中
【发布时间】:2018-10-26 10:23:49
【问题描述】:

以下代码用于显示电子钱包类型应用的 UITableView。但是tableview没有出现。

 import UIKit
class walletViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {


    @IBOutlet weak var tableView: UITableView!

    @IBOutlet weak var searchBar: UISearchBar!

    @IBOutlet weak var filterImageView: UIImageView!



    let imageList = ["user1","user2","user3"]

    let titleTist = ["John","Anna","Eva"]

    let userPaid = ["Last Paid $100","Last Paid $200","Last Paid $150"]


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        tableView.delegate = self;
        tableView.dataSource = self;
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }




     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return titleTist.count
    }


     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! EwalletTableViewCell

        // Configure the cell...

        cell.cellTitle.text = titleTist[indexPath.row]
        cell.userStatus.text = userPaid[indexPath.row]

        cell.cellImageView.image = UIImage(named: imageList[indexPath.row])

        return cell
    }


    @IBAction func backButton(_ sender: Any) {

        dismiss(animated: true, completion: nil)
    }

}
This following code is about the cellview and the items present in it.
import UIKit

class EwalletTableViewCell: UITableViewCell {



    @IBOutlet weak var userImageView: UIImageView!

    @IBOutlet weak var UserName: UILabel!


    @IBOutlet weak var UserPaidInfo: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    @IBAction func paidButton(_ sender: Any) {

    }

}

【问题讨论】:

标签: uitableview swift4 xcode9.3


【解决方案1】:

约束存在一些错误。它已修复。一切都很好。谢谢大家。

【讨论】:

    【解决方案2】:

    对于tablview首先你需要一步一步检查这个东西

    • 检查您给出的行数不为零
    • 检查 Tableview Datasource 方法是否被调用?
    • 在 Swift 中你必须在 viewController 旁边导入 UITableViewDelegate、UITableViewDataSource

    【讨论】:

      【解决方案3】:

      以下几行替换

      cell.UserName.text = titleTist[indexPath.row]
      cell.UserPaidInfo.text = userPaid[indexPath.row]
      cell.userImageView.image = UIImage(named: imageList[indexPath.row])
      

      cell.cellTitle.text = titleTist[indexPath.row]
      cell.userStatus.text = userPaid[indexPath.row]
      cell.cellImageView.image = UIImage(named: imageList[indexPath.row])
      

      【讨论】:

        猜你喜欢
        • 2017-01-18
        • 1970-01-01
        • 1970-01-01
        • 2012-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-10
        • 2013-10-09
        相关资源
        最近更新 更多