Here i have two classes. How do I make JournalPage
call JournalEntryController
didSubmit
method.
protocol JournalPageDelegate {
func didSubmit(for commentText: String)
}
class JournalPage: UIViewController, UITextViewDelegate {
var delegate: JournalPageDelegate?
fileprivate let textView: UITextView = {
let textView = UITextView()
let attributedText = NSMutableAttributedString(string: "Enter Text Here.", attributes: [NSAttributedStringKey.font: UIFont.boldSystemFont(ofSize: 18)])
textView.textColor = UIColor.black
textView.backgroundColor = UIColor.white
textView.becomeFirstResponder()
textView.selectedTextRange = textView.textRange(from: textView.beginningOfDocument, to: textView.beginningOfDocument)
textView.attributedText = attributedText
return textView
}()
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Save", style: .plain, target: self, action: #selector(save))
}
@objc func save() {
print("saving")
guard let commentText = textView.text else { return }
delegate?.didSubmit(for: commentText)
}
And here is the class where I want to call the method.
class JournalEntryController: UIPageViewController, UIPageViewControllerDataSource, JournalPageDelegate {
func didSubmit(for commentText: String) {
print("Testing for text")
}
}
And for some reason, I don't see "Testing" on the console when I tap save on JournalPage
class. How do I make JournalPage
call JournalEntryController
didSubmit
method?