Więc dodałem widok tabeli do normalnego kontrolera widoku i wewnątrz tego widoku tabeli wykonałem prototypową komórkę. Zrobiłem trochę pracy, aby komórka się pojawiła, ale nie „t. Jak to naprawić? Oto mój kod:
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) {
}
}
Odpowiedzi:
0 dla odpowiedzi № 1Musisz return cell
po zdobyciu komórki i daniu jej do wyświetlenia. Spróbuj czegoś takiego
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!
}
Jeśli chcesz to zrobić w scenorysie, możeszzamiast tego dodaj etykietę do komórki prototypowej w serii ujęć, ustaw wartość całkowitą dla znacznika etykiety, a następnie znajdź etykietę, dodając te dwa wiersze po zakończeniu let cell = ...
let label = cell.viewWithTag(100) as UILabel!
label.text = fillTableViewArray[indexPath.row]
Mam nadzieję, że pomoże to rozwiązać problem