John
John

Reputation: 8548

pushControllerWithName not working

I'm trying to push an interface controller with the identifier "InterfaceControllerTodoItemTapped" programmatically (deployment target iOS 8.2) when a WKInterfaceTable row is tapped:

[self pushControllerWithName:@"InterfaceControllerTodoItemTapped" context:nil];

The source controller is part of a page-based navigation setup.

The identifier field of the receiving interface controller is set to "InterfaceControllerTodoItemTapped".

Problem: Although the above push command is reached (confirmed using a breakpoint), the InterfaceControllerTodoItemTapped is not shown and its method awakeWithContext is not being called (confirmed using a breakpoint).

Upvotes: 5

Views: 2861

Answers (3)

iOS Lifee
iOS Lifee

Reputation: 2201

For Swift 5+ Versions

self.pushController(withName: "SecondWKVC", context: nil)

Upvotes: 0

San
San

Reputation: 1796

If the Interface Controller you are pushing is hierarchical navigation then make sure -

Identifier field in Attributes Inspector is set.

[self pushControllerWithName:@"SSWatchTableInterfaceController" context:nil];

enter image description here

Upvotes: 6

John
John

Reputation: 8548

Apple's documentation states that one has to choose either a page-based or a hierarchical navigation. They are mutually exclusive.

Therefore, presenting a controller using pushControllerWithName does not work with page-based navigation.

The solution is to present the controller modally using the following method:

[self presentControllerWithName:@"InterfaceControllerTodoItemTapped" context:nil];

Upvotes: 14

Related Questions