私は、ユーザーが任意の日付を選択すると、別のviewControllerにリダイレクトされるカスタムカレンダーを作成するIOSを初めて使いました。デリゲートを使用して別のView Controllerを開く?
私はカレンダーを作成するには、このリンクを使用: https://github.com/Akhilendra/calenderAppiOS
私はデリゲートでそれを行っているが、私は私が間違って何をしたかを把握することはできません。
マイコード:
protocol SelectedDateDelagate: class {
func openAppointmentDetails()
}
class CalenderView: UIView, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, MonthViewDelegate {
weak var delegate: SelectedDateDelagate?
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell=collectionView.cellForItem(at: indexPath)
cell?.backgroundColor=Colors.darkRed
let lbl = cell?.subviews[1] as! UILabel
lbl.textColor=UIColor.yellow
let calcDate = indexPath.row-firstWeekDayOfMonth+2
print("u selected date",calcDate,monthName)
delegate?.openAppointmentDetails()
}
}
class ViewController: UIViewController,SelectedDateDelagate {
func openAppointmentDetails() {
let myVC = storyboard?.instantiateViewController(withIdentifier: "appointmentDetailsVC") as! AppointmentDetailsViewController
navigationController?.pushViewController(myVC, animated: true)
}
}
私は何もやることが起こるの日付をクリックしたとき、今の問題があります。
あなたはこれをデバッグしましたか?それをナビゲーションコントローラにプッシュする前に、 'myVC'の値は何ですか?また、 'delegate'は' openAppointmentDetails() 'を呼び出す前に設定されていますか? – halileohalilei