如何在按钮单击时实现导航
我的项目首先使用 Three20 框架来处理导航。但由于一些问题,我必须删除 Three20 部分。所以我重新设计我的应用程序。 我想做的是当用户触摸按钮时显示详细视图。我创建了一个新的主窗口,因为之前没有。它没有导航控制器。 我用了
DetailViewController *detailViewController=[[DetailViewController alloc] init]; [self.navigationController PushviewController:detailviewControllerAnimated:YES]
在按钮触摸事件中。 但是当我运行应用程序时,按钮触摸没有任何反应。没有显示警告或错误。 我已经在其他应用程序中完成了此操作,但在这里不起作用。
my project first used the Three20 frame work for handling navigation.But due to some problems i ha to remove the three20 part.So im redesigning my app.
what im trying to do is show a detail view when user touches a button.I created a new mainwindow as there was none earlier.It does not have a navigation controller.
i used
DetailViewController *detailViewController=[[DetailViewController alloc] init];
[self.navigationController pushviewController:detailviewController animated:YES]
in the buttos touch up event.
but when i run the app nothings hapens on button touch.No warnings or errors are shown.
Ive done this in other apps but it just doesnt work here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您没有使用 UINavigationController,因此 UIViewController 的 navigationController 属性将保持为零。 “编译方面”没有问题,因为该属性存在,但编译器不知道该属性将保持为零,因此不会显示警告/错误。
Objective-C 中允许向 nil 对象发送消息,因此代码在运行时不会崩溃并且不执行任何操作。
如果你想获得你的代码&运行时,您需要将根 UIViewController 放入 UINavigationController 中。一旦 UIViewController 显示在 UINavigationController 中,该属性将自动设置为 UINavigationController。
编辑:您可以使用类似的东西,而不是显示 someController,而是将其“封装”在 UINavigationController 中并显示该控制器。
Since you are not using a UINavigationController, the navigationController property of the your UIViewController will remain nil. "Compile-wise" there's no problem, since the property exists, but the compiler does not know the property will remain nil, hence no warnings/errors are shown.
Sending a message to a nil object is allowed in Objective-C, hence the code doesn't crash and does nothing when being run.
If you want to get your code up & running, you'll need to put the root UIViewController in a UINavigationController. Once the UIViewController is shown in a UINavigationController, the property will be set to the UINavigationController automatically.
Edit: You could use something like this, instead of showing someController, "encapsulate" it in a UINavigationController and show that controller.