UITableView не появляется в iPhone - PullRequest
0 голосов
/ 16 мая 2018

Следующий код предназначен для отображения UITableView для приложения типа электронного кошелька. Но табличное представление не появляется.

 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) {

    }

}

enter image description here

enter image description here

Ответы [ 3 ]

0 голосов
/ 16 мая 2018

Для просмотра таблицы сначала вам нужно проверить эту вещь шаг за шагом

  • Проверьте, что число строк не равно нулю
  • Проверьте, вызывается метод источника данных Tableview или нет?
  • В Swift вы должны импортировать UITableViewDelegate, UITableViewDataSource рядом с viewController
0 голосов
/ 31 мая 2018

Произошли некоторые ошибки с ограничениями. Это было исправлено. И все хорошо. Спасибо всем.

0 голосов
/ 16 мая 2018

заменить следующие строки

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])
...