【问题标题】:JTAppleCalendar cell inside TableView ? in Swift 3TableView 中的 JTAppleCalendar 单元格?在斯威夫特 3
【发布时间】:2023-03-31 11:06:02
【问题描述】:

我正在使用 JTAppleCalendar -> https://github.com/patchthecode/JTAppleCalendar 日历插件,我想将 ColectionView 单元格放置在 TableView 单元格中,并且我想在添加的事件中显示每个单元格(在 tableview 单元格内),但是当我连接插座时给我;

错误:非法配置:从 ViewController 到 UITableView 的 tableView 出口无效。插座不能连接到重复的内容。

我该如何解决?

CellView.swift

import JTAppleCalendar

class CellView: JTAppleCell {
    @IBOutlet var selectedView: UIView!
    @IBOutlet var dayLabel: UILabel!
    @IBOutlet var Label: UILabel!
}

Cell.Swift

import UIKit

class Cell: UITableViewCell {

    @IBOutlet weak var label : UILabel!

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)


    }
}

ViewController.Swift

@IBOutlet weak var tableView: UITableView!


  extension ViewController: UITableViewDelegate, UITableViewDataSource {

        func numberOfSections(in tableView: UITableView) -> Int {
            return  1
        }

        func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return  5
        }

        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell

            cell.label?.text = String(indexPath.row)

            return cell
        }

        func tableView(_ tableView: UITableView,didSelectRowAt indexPath: IndexPath) {
            tableView.deselectRow(at: indexPath, animated: true)
        }
    }

下面是我的屏幕;

【问题讨论】:

  • 如果您创建一个新的 github 问题,并在那里上传问题的一个小 zip 文件,我可以提供帮助。那我就回这里来回答吧。

标签: ios uitableview swift3 uicollectionview jtapplecalendar


【解决方案1】:

您需要创建 CollectionViewCell 的自定义类并在其上使用 IBOutlets。现在您已经在 ViewController 的类中获取了 customCell 的视图 IBOutlets。

使用标签属性,您可以将该视图与单元格链接。如下在 cellForItemAtIndexPath 中。

let label:UILabel = cell.viewWithTag(101) as! UILabel // 101 tag need to set in storyboard related view 

如何为视图分配标签

https://stackoverflow.com/a/31782616/3901620

【讨论】:

  • 那么还是会出现这个问题。
  • 我添加了我的表格视图代码,你能告诉我如何修复它吗?
  • 单元格的标签在哪里声明?
  • 我添加了 Cell.Swift
猜你喜欢
  • 2017-03-24
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-15
  • 1970-01-01
  • 1970-01-01
  • 2017-07-22
相关资源
最近更新 更多