WatchKit: WKInterfaceButton Doesn’t Pass Reference to IBAction Method
| Originator: | SlaunchaMan | ||
| Number: | rdar://19415424 | Date Originated: | 1/8/2015 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | Xcode 6.2 Beta 3 |
| Classification: | Enhancement | Reproducible: | Always |
Summary:
IBAction methods for WKInterfaceButtons take this form:
@IBAction func buttonPressed() {
}
Without a “sender” parameter like UIButton gives, it’s hard to reuse a method for multiple buttons; instead, you need to write one method for each button.
Steps to Reproduce:
1. Create a WKInterfaceController in a storyboard for your WatchKit extension, with an accompanying WKInterfaceController subclass.
2. Add a WKInterfaceButton to the interface controller.
3. Control-drag from the button to the WKInterfaceController subclass’ code in the Assistant Editor.
4. Select “Action” from the pop-up.
Expected Results:
You can provide a “sender” parameter.
Actual Results:
You cannot provide a “sender” parameter.
Version:
Xcode 6.2 Beta 3
Notes:
Consider an interface controller with three buttons: A, B, and C. Each button has its own property, so right now you have to write this:
@IBAction func buttonAPressed() {
buttonPressed(buttonA)
}
@IBAction func buttonBPressed() {
buttonPressed(buttonB)
}
@IBAction func buttonCPressed() {
buttonPressed(buttonC)
}
func buttonPressed(button: WKInterfaceButton) {
if button == buttonA {
// do something
}
else if button == buttonB {
// do something
}
else if button == buttonC {
// do something
}
}
If we were able to send a “sender” parameter, we could do with just the last function in that code, linking it to each WKInterfaceButton.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!