Основная проблема с табличным представлением - PullRequest
0 голосов
/ 08 октября 2018

Я довольно новичок в Swift и пытаюсь настроить супер простое табличное представление, и ничего из того, что я пробовал, не сработало.Он строит без проблем, но моя таблица невидима на симуляторе.Что я делаю не так?

class ViewController: UIViewController, UITableViewDelegate, 
UITableViewDataSource {

var currentNames: Array = ["Name1", "Name2", "Name3", "Name4", "Name5", "Name6", "Name7", "Name8", "Name9", "Name10"]
var currentDays: Array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
@IBOutlet weak var tableView: UITableView!

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

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    let currDays = currentDays[indexPath.row]
    cell.textLabel?.text = currentNames[indexPath.row]
    cell.detailTextLabel?.text = String(currDays)
    return(cell)
}

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
}

1 Ответ

0 голосов
/ 08 октября 2018

Пожалуйста, подтвердите, что вы использовали следующие строки в ViewDidLoad после создания выхода tableView

tableView.delegate = self
tableView.dataSource = self

как

class ViewController: UIViewController, UITableViewDelegate, 
UITableViewDataSource {

 @IBOutlet weak var tableView: UITableView!

 override func viewDidLoad() {
     super.viewDidLoad()
     tableView.delegate = self
     tableView.dataSource = self
 }

var currentNames: Array = ["Name1", "Name2", "Name3", "Name4", "Name5", 
    "Name6", "Name7", "Name8", "Name9", "Name10"]
var currentDays: Array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

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

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    let currDays = currentDays[indexPath.row]
    cell.textLabel?.text = currentNames[indexPath.row]
    cell.detailTextLabel?.text = String(currDays)
    return(cell)
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...