我已经在我的应用程序中实现了XLPagerTabStrip库,现在在我的Container VC中,我有一个日历,当我单击该日历时,我会调用一个代表我选择的日期值的委托函数。我有3个ChildVC名称,AcceptedBookingVC,PendingBookingVC和HistoryBookingVC。现在我想将selectedDate传递给当前打开的VC。我该如何通过?我已经使用了委托,但是它没有传递我的数据。这是我的代码,
protocol BookingContainerDelegate {
func selectedDate(selectedDate:String)
}
func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
let selected = calendar.selectedDate
let dateFormatter1: DateFormatter = DateFormatter()
dateFormatter1.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
dateFormatter1.dateFormat = "yyyy-MM-dd"
print("\(dateFormatter1.string(from: selected!))")
selectDate = dateFormatter1.string(from: selected!)
dateDelegate?.selectedDate(selectedDate: dateFormatter1.string(from: selected!))
self.popViewTopConstraint.constant = -300
popUpShowing = false
UIView.animate(withDuration: 0.3) {
self.view.layoutIfNeeded()
}
}
当我在Container VC中调用子vc时,这是XLPager的代码,
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child1 = UIStoryboard().loadAcceptedBookingVC()
child1.dateDelegate = self
child1.selectDate = selectDate
child1.itemInfo = "Accepted"
let child2 = UIStoryboard().loadPendingBookingVC()
child2.selectDate = selectDate
child2.itemInfo = "Pending"
let child3 = UIStoryboard().loadHistoryBookingVC()
child3.selectDate = selectDate
child3.itemInfo = " History"
return [child1,child2,child3]
}
这是Child VC,我正在打电话给我的代表,但它没有值,
extension AcceptedBookingVC : BookingContainerDelegate
{ func selectedDate(selectedDate:String){ 打印(selectedDate) 日期= selectedDate } }