我试图将 tableview 放入 UIViewController 中,但我无法控制从 UITableView 拖动到我的 View Controller 中以创建导出。当我尝试拖动时,它拒绝提示 socket 。我什至尝试自己制作一个 socket ,然后从 View Controller 类拖动到 TableView ,但它拒绝链接。
这是我的 Tableview 类(class):
季节细胞类
import UIKit
class SeasonCell: UITableViewCell {
@IBOutlet weak var seasonLabel: UILabel!
}
季节类
class Season: NSObject {
var name: String
init(name: String){
self.name = name
}
}
View Controller
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!
}
}
最佳答案
您需要 1) 为 View Controller 的类指定一个唯一的名称。这又创建了一个类型。 2)然后您需要打开Storyboard,并将包含tableview的 View Controller 的类设置为您刚刚创建的类型。这将允许您使用控件拖动来创建 socket 。
设置storyboard中 View Controller 类型的方法如下:
关于ios - 无法为 UITableView 创建导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54966016/