Skip to content

UXNavigationDelegate

UXNavigationDelegate tells you when a form becomes visible in a UXNavigationController and when it stops being visible. Both methods are optional.

#use <UXKit> // or #import "UXNavigationController.xc"
protocol UXNavigationDelegate {
optional void formWillShow(UXNavigationController* n, UXView* content, i32 depth);
optional void formDidHide(UXNavigationController* n, UXView* content, i32 depth);
}
nav.setDelegate((UXNavigationDelegate*)self);

The delegate is held weakly, like other delegates, so the controller never keeps its owner alive.

Implement the two methods as a pair. Each fires in two situations, and it is easy to handle only one:

formWillShowa form is pushed and a form is re-revealed when the one above it pops
formDidHidea form is covered by a push and a form is popped off

A detail screen that starts a timer in formWillShow and stops it in formDidHide behaves correctly whether the user navigates forward, comes back, or goes deeper and returns. If you handle only the push and pop cases, a covered screen keeps working while invisible, a common cause of a mobile app doing hidden work.

void formWillShow(UXNavigationController* n, UXView* content, i32 depth) {
if (content == (UXView*)detail) { self.startPolling(); }
}
void formDidHide(UXNavigationController* n, UXView* content, i32 depth) {
if (content == (UXView*)detail) { self.stopPolling(); }
}

formWillShow · formDidHide

optional void formWillShow(UXNavigationController* n, UXView* content, i32 depth)

content is about to become the visible top. depth is the stack depth it will occupy, counting from 1.

On a first push it fires before the view is added to the tree, so populate the view here: the content is yours and is not on screen yet.

optional void formDidHide(UXNavigationController* n, UXView* content, i32 depth)

content has stopped being the top.

A pop does not destroy the view. It stays attached and hidden, so pushing the same form again re-reveals it instead of rebuilding it. Do not use this method for teardown; release nothing you would need if the form comes back.

A platform’s own back affordance (a swipe, a hardware key, a navigation bar button) surfaces as an ordinary pop, reported through the same two methods. There is no separate “the user went back” notification.