I've found some problems when trying to access the UITableViewDelegate
methods, inside an instantiated UITableViewCell
class.
I'm trying to access the
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {}
and the functions doesn't fire, and I guess that's because I've some issues trying to set the delegate.
The code goes as it follows:
import UIKit
class TableViewCell: UITableViewCell, UITextViewDelegate {
@IBOutlet var titleLabel: UILabel!
@IBOutlet var textView: UITextView!
@IBOutlet var postImageView: UIImageView!
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {
print("link tapped")
return true
}
init() {
super.init()
textView.delegate = self
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
On the super.init()
line this error is shown
TableViewCell.swift - "Must call a designated initializer of the superclass" 'UITableViewCell'
Any tip on how to overpass this ?
Thanks in advance
FINAL EDIT
I've done what I really wanted to do.
Instead of using the UITextFieldDelegate inside the UITableViewCell Class, I've added the UITextFieldDelegate to the ViewController that uses the cell itself, and on the cell configuration just did:
cell.textView.degelate = Self
, then I've implemented the delegate function of
func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange) -> Bool {}
Thanks for answering boys.