This is from the custom cell:
This is from the Storyboard:
Anyone have any idea how to make these two buttons do the exact same action? Is it possible to make multiple buttons do one action?
This is from the custom cell:
This is from the Storyboard:
Anyone have any idea how to make these two buttons do the exact same action? Is it possible to make multiple buttons do one action?
I usually keep the backing UIView
s and UIViewController
s very thin in my applications and I create classes that do the actual heavy lifting. This makes for cleaner code and easier reuse.
class Player {
static func play() { // Static makes it easier to call from every class, assuming you only play one song at a time
// play logic goes here
}
}
class MyView: UIView {
@IBAction func play() { // connect in IB in your .xib
Player.play()
}
}
class MyViewController: UIViewController {
@IBAction func play() { // connect in IB in your storyboard
Player.play()
}
}
You need two IBAction methods in separate classes (for cell and for view controller). If you want to minimize repeating code try to make a special class with this functionality and then call its method in two IBAction methods.
Also you can take a look at Command design pattern for this purpose.