【发布时间】:2019-03-03 05:58:57
【问题描述】:
我试图在 UIViewController 中放置一个 tableview,但我无法控制从 UITableView 拖动到我的视图控制器中以创建一个插座。当我尝试拖动时,它拒绝提示插座。我什至尝试自己制作一个插座,然后从视图控制器类拖动到表格视图,但它拒绝链接。
这是我的 Tableview 类:
季节单元班
import UIKit
class SeasonCell: UITableViewCell {
@IBOutlet weak var seasonLabel: UILabel!
}
季节班
class Season: NSObject {
var name: String
init(name: String){
self.name = name
}
}
视图控制器
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
var seasons = [Season]()
//created myself, wont link
@IBOutlet weak var seasonsTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
seasons.append(Season(name: "2018 Cross Country Season"))
seasonsTableView.delegate = self
seasonsTableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return seasons.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "seasonCell", for: indexPath) as? SeasonCell
// Configure the cell...
let thisSeason = seasons[indexPath.row]
cell?.seasonLabel?.text = thisSeason.name
return cell!
}
}
【问题讨论】:
-
将视图控制器的名称改为SeasonsViewController。
-
你在场景中放了什么类名?
标签: ios swift uitableview