Тому я додав перегляд таблиці до контролера нормального вигляду, і всередині цього перегляду таблиць я зробив прототипу. Ive зробив деяку роботу, щоб клітина з'явилася, але вона перемогла "т. Як це виправити? Ось мій код:
import UIKit
class NewsScreenViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var trendingButton: UITabBarItem!
@IBOutlet weak var newestButton: UITabBarItem!
@IBOutlet weak var topJournalists: UITabBarItem!
@IBOutlet weak var tabBar: UITabBar!
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
return UITableViewCell()
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
}
Відповіді:
0 для відповіді № 1Тобі потрібно return cell
після того, як ви отримаєте клітинку і дайте їй щось для відображення. Спробуйте щось подібне
let fillTableViewArray = [String]()
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReuseableCellWithIdentifier("cell")
//now that you have that cell you have to put something into it. For example an Array of strings, can be used to fill the table view
cell!.textLabel?.text = fillTableViewArray[indexPath.row]
return cell!
}
Якщо ви хочете зробити це в аркуші розкадрування, ви можетезамість того, щоб додати мітку до осередку прототипу на аркуші розкадрування, встановити ціле значення для мітки "s", а потім знайти мітку, додавши ці дві лінії після let cell = ...
let label = cell.viewWithTag(100) as UILabel!
label.text = fillTableViewArray[indexPath.row]
Сподіваюся, це допоможе вирішити проблему