Reputation: 8651
I have a VC that contains a containerview that holds a table view. = Root VC holds the tableview
I have setup a delegate from the tableview to the root VC that checks if the screen is being scrolled up or down, and this works.
What I now want to do is to have a delegate between root VC to the table view. When a button is clicked in the root VC I want to fire a function in the table view.
This will make the viewcontrollers have delegates implemented on each other - is that a problem?
eg:
class RootVC, tableViewDelegate
class Tableview, RootVCDelegate
My delegate looks like this:
protocol RootVCDelegate: class {
func RootVCDidTouchGrid(controller: RootViewController)
}
class rootvc { ...
weak var delegate: RootVCDelegate?
@IBAction func gridButtonDidTouch(sender: AnyObject) {
delegate?.RootVCDidTouchGrid(self)
}
Then in table view:
class tableview, RootVCDelegate {..
func RootVCDidTouchGrid(controller: RootViewController) {
println("touched!")
}
So why is never println("touched!")
fired?
Thanks
Upvotes: 2
Views: 406
Reputation: 2600
RootVCDelegate
in your RootViewController
TableView
class conforms to RootVCDelegate
delegate
property of RootViewController
to your TableView
instance.You're missing something like:
class tableview, RootVCDelegate {..
override func viewDidLoad() {
super.viewDidLoad()
rootViewController.delegate = self
}
func RootVCDidTouchGrid(controller: RootViewController) {
println("touched!")
}
}
Upvotes: 1
Reputation: 10951
It looks like you forgot to set a delegate. Just set it delegate = self
in viewDidLoad
Upvotes: 0
Reputation: 449
please define delegate value in view didload:
delegate = self
Upvotes: 0