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
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()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With