Reputation: 7858
This is the first time I'm working with delegate
in swift. I've a table view with fixed three number of rows and every row has a seprate .xib
for cell.
I'm adjusting the height of each cell based on the data I am getting in the cell. So as the tableView
is loaded before and the cells are loaded after so I've defined a protocol
in UITableViewCell
class.
Above CalenderTimeTableViewCell
class I've:
protocol ReloadingTable {
func updateTableView()
}
Inside this class above awakeFromNib()
I've: var myDelegate: ReloadingTable?
and in the method I'm getting data (using Alamofire) I'm calling self.myDelegate?.updateTableView()
.
In the viewController
in which I've the tableView
first of all I extended the class ReloadingTable
and in this class I've:
func updateTableView() {
tableView.reloadData()
}
By applying break points the code did get to the self.myDelegate?.updateTableView()
but in viewController
updateTableView
method is not being called.
Upvotes: 1
Views: 741
Reputation: 15748
As @vadian has commented you should assign target class to myDelegate
in cellForRowAt function assign target class to my delegate
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CalenderTimeTableViewCell
cell.myDelegate = self
//Other
}
Upvotes: 1