ios - 无法为 UITableView 创建导出

标签 ios swift uitableview

我试图将 tableview 放入 UIViewController 中,但我无法控制从 UITableView 拖动到我的 View Controller 中以创建导出。当我尝试拖动时,它拒绝提示 socket 。我什至尝试自己制作一个 socket ,然后从 View Controller 类拖动到 TableView ,但它拒绝链接。

Here is my workspace

这是我的 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 类型的方法如下:

enter image description here

关于ios - 无法为 UITableView 创建导出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54966016/

相关文章:

ios - 如何修复 "nib but didn' t get a UITableView"error?

ios - UITableViewCell 左侧颜色

iphone - 带有阴影的 UILabel 在自动收缩时更改阴影偏移

ios - NSOperationQueue添加后台线程操作

macos - 在 10.10 上,NSPopover 中的 NSViewController 通过从 swift 中的 NSStatusItem 中转出

swift - GooglePlus 登录使用 Swift 不工作

ios - 如何创建新的 NSUrlSession(第一个 session 失效后)

ios - 如何在 AVAudioRecorder 中控制 Opus 比特率

ios - 使用 CGAffineTransform 和 PanGestureRecognizer 旋转 ImageView

ios - UICollectionView 委托(delegate)方法 "didSelectItemAtIndexPath"在 UITableviewCell 中使用 UICollection View 时未调用