1

I have a custom popup view that has a UIDatePicker. This, when changed, changes the date of the save time. I also want the label on the in the CustomCell to be updated if the date has changed. I have used a delegate protocol to update the table but I cannot get this protocol to transfer the information on save. Can you help? I think I have hooked up all the correct code in the viewController class. I have tried this answer but I cannot set the delegate in the target class and there isn't a segue A Swift example of Custom Views for Data Input (custom in-app keyboard)

protocol DatePopUpViewDelegate: class {

func pastDate(date: String) // date that is chosen in picker
func isPastDateSet(isSet: Bool) // has chosen new date

}


@IBDesignable class DatePopUpView: UIView {

var delegate: DatePopUpViewDelegate?


func loadViewFromNib() -> UIView {

let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "DatePopUp", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

delegate?.isPastDateSet(false)
return view
}

// close popup
@IBAction func closeButtonDatePopUp(sender: AnyObject) {
if dateToSave != openTime {
  if let dateToSave = dateToSave {
    SaveData.changedSaveTime = dateToSave
    delegate?.pastDate(dateToSave)
    delegate?.isPastDateSet(true)
  }

} else {
  SaveData.changedSaveTime = ""
  delegate?.isPastDateSet(false)
}
}




class SaveTableViewCell: UITableViewCell, DatePopUpViewDelegate {

var changeDateLabel: Bool = false

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code

  changeDateLabel = false

  datePopUpViewControllert.delegate = self
}

// delegate functions
func pastDate(date: String) {
self.labelDate = date
print("del date \(date)")
}

func isPastDateSet(isSet: Bool) {
self.changeDateLabel = isSet
print("is set by delegate \(isSet)")
}
Community
  • 1
  • 1
SashaZ
  • 393
  • 7
  • 20

0 Answers0