Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selector not called on selecting menu item after force touch

I have this code, for responding to a menu item being tapped after a force touch:

class InterfaceController: WKInterfaceController {
    override init() {
        super.init()

        self.addMenuItemWithItemIcon(WKMenuItemIcon.Pause, title: "Pause", action: Selector("test"))
    }

    func test() {
        print("test")
    }
}

When I force touch, the menu appears. When I tap the "Pause" button, test() is not called.

Any ideas why this might be?

like image 606
Andrew Avatar asked Sep 02 '15 17:09

Andrew


2 Answers

Solved.

Though its the result of a silly mistake (aren't most problems?), I think this is something a lot of people will run into, so I'll keep it here with my answer.

I enabled force touch on the simulator, so I could show the menu. When I'm tapping again on the button, force touch is still enabled, so I'm force touching, thus dismissing the menu.

Solution: Disable force touch before tapping a menu button.

like image 95
Andrew Avatar answered Oct 13 '22 01:10

Andrew


I wanted to comment with my thanks for this solution but I don't have the rep so I'll begin with, THANKS!

However I can also add an addendum to the solution by pointing out the shortcut keys are really handy here for switching between force press pressures.

⇧⌘1 - for shallow pressure (tap)

⇧⌘2 - for deep pressure (force press)

Make sure the iOS Simulator (watch) is focussed and you'll be good to go.

like image 34
mbarnettjones Avatar answered Oct 12 '22 23:10

mbarnettjones