Aftab Ahmed
Aftab Ahmed

Reputation: 113

Pull to refresh in Apple Watch app in Swift

I see a pull to refresh in the Apple Watch mail app, but I don't see how to implement such a scenario. Kindly give some insight into how to achieve pull to refresh in Apple Watch app in Swift.

Thanks...

Upvotes: 2

Views: 1861

Answers (1)

David Pasztor
David Pasztor

Reputation: 54706

You should add a pan gesture recognizer to your Interface Controller and then you can write the code for refreshing your data.

You have to add the gesture recognizer to your InterfaceController in InterfaceBuilder, then connect an Action to it. Have a look at Apple's WKInterfaceCatalog example code, especially the GestureDetailController class and Gestures scene in Interface builder.

You can decide to use a Swipe gesture recognizer or Pan gesture recognizer.

The IBAction for Swipe gesture recognizer is:

@IBAction func swipeRecognized(_ sender: AnyObject) {
    //update your UI
}

And for the Pan gesture recognizer:

@IBAction func panRecognized(_ sender: AnyObject) {
    if let panGesture = sender as? WKPanGestureRecognizer {
        //Update your UI
    }
}

Upvotes: 1

Related Questions