【问题标题】:Access Parent tableViewCell from Child CollectionViewCell从子 CollectionViewCell 访问父 tableViewCell
【发布时间】:2018-07-18 07:27:46
【问题描述】:

描绘一个 tableViewCell 的图像。在一个 tableViewCell 里面有一些内容和一个 CollectionView(显示日期的灰色区域)。 根据集合视图中的日期及其滚动,我必须显示年份和月份(“2018 年 12 月”:图像中是静态的)。

这是我的 JTAppleCalender cellForItemAt 方法:

   func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {

        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CalenderCell", for: indexPath) as! CalenderCell

        cell.lblDate.text = cellState.text
        formatter.dateFormat = "EEE"
        cell.lblDay.text = formatter.string(from: cellState.date)

        formatter.dateFormat = "MMMM YYYY"
        print(formatter.string(from: cellState.date))

        formatter.dateFormat = "dd-MM-yyyy"
        print(formatter.string(from: cellState.date))

        if(pickup_dates .contains(formatter.string(from: cellState.date))){
            let index = pickup_dates.index(of: formatter.string(from: cellState.date))
            let dictinfoDelivery = self.infoDelivery.object(at: index) as! NSDictionary
            cell.lblPrice.text = dictinfoDelivery .value(forKey: "total_price_format") as? String
            cell.isUserInteractionEnabled = true
        }
        else{
            cell.lblPrice.text = ""
            cell.isUserInteractionEnabled = false
        }

        return cell
    }

我正在尝试从该方法内部访问 tableView label("December 2018") 但无法访问。 如何从子 collectionViewCell 访问这个 TableViewCell 标签? 我的要求是更改 tableViewCell 中的 2-3 内容(价格,数量)wrt 在子 CollectionView 中选择的日期。

【问题讨论】:

  • CollectionViewTableViewCell 内部。所以它的delegate 也将在那里,您可以直接更新TableViewCell 元素。有什么问题?
  • 我不明白你的tableviewCell的结构。它在集合视图内部,因此您拥有“cellForItem”的类必须是单元类。如果不是,你必须让我们了解你使用什么结构来获得这个(我可以告诉你,你可能把事情搞砸了)
  • 我不知道如何更新单元格。现在我能做到了。感谢您回复@Kamran

标签: ios swift uitableview uicollectionview jtapplecalendar


【解决方案1】:

请试试这个

  guard  let lbl = (self.yourTableView.cellForRow(at: [NSIndexPath(row: 0, section: 0) as IndexPath]) as! yourCellNameInTableView).labelName else {
        return
   }
  lbl.text = "Your text"

请传递您的行号和节号。它可能对你有帮助。谢谢你

【讨论】:

  • 根据更新的语法更新代码后它工作了。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
相关资源
最近更新 更多