pushControllerWithName 不工作

pushControllerWithName not working

我正在尝试在点击 WKInterfaceTable 行时以编程方式推送具有标识符 "InterfaceControllerTodoItemTapped" 的接口控制器(部署目标 iOS 8.2):

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

源控制器是基于页面的导航设置的一部分。

接收接口控制器的标识符字段设置为"InterfaceControllerTodoItemTapped"。

问题:虽然达到了上面的push命令(使用断点确认),但是InterfaceControllerTodoItemTapped没有显示并且没有调用它的方法awakeWithContext(使用断点确认) .

Apple 的 documentation 声明必须选择基于页面的导航或分层导航。它们是相互排斥的。

因此,使用 pushControllerWithName 呈现控制器不适用于基于页面的导航。

解决方案是使用以下方法以模态方式呈现控制器:

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

如果您推送的界面控制器是分层导航,那么请确保 -

Identifier field in Attributes Inspector is set.

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

对于 Swift 5+ 版本

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