Reputation: 891
I am doing a simple customtableview project.I have viewController.swift and customcell.swift file.I have a method inside viewcontroller file.How do i call that method from customcell file.any help will be appreciated.thanks in advance
Upvotes: 3
Views: 2872
Reputation: 2805
Here are a few ways to accomplish communication between your objects.
There are other ways to go about this, but those are the first three that come to mind. Hope that gave you a few ideas on how to proceed.
Below is a simple example of the delegation pattern.
Your parent would look like this:
protocol ParentProtocol : class
{
func method()
}
class Parent
{
var child : Child
init () {
child = Child()
child.delegate = self
}
}
extension Parent : ParentProtocol {
func method() {
println("Hello")
}
}
Your child would look like this:
class Child
{
weak var delegate : ParentProtocol?
func callDelegate () {
delegate?.method()
}
}
Upvotes: 11