在 UINavigationController 中推送另一个视图?
如何使用导航控制器中的按钮推送视图? 我尝试遵循这个例子: http://www.cimgf.com/ 2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/
这正是我所需要的,我有一个UITabBarController
有 4 个选项卡,其中一个是 UINavigationController
。我想从第一个视图中推送包含导航控制器的视图 - 这是一个简单的 UIView。它不起作用,我也尝试使用以编程方式创建的按钮,但没有任何反应。有什么指点吗?
这是我的代码
@interface HomeViewController : UIViewController {
}
-(IBAction)pushViewController:(id)sender;
@end
---
#import "HomeViewController.h"
#import "NewViewController.h"
@implementation HomeViewController
-(IBAction)pushViewController:(id)sender {
NewViewController *controller = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
}
,这也是带有连接的屏幕截图 http://imageshack.us/photo/my-images/847/screenshot20110719at620。 png/
我已经尝试了你们的建议,但仍然没有任何结果,按钮(无论它们是在 Interface 中创建的Builder
或以编程方式)的行为就像它们没有链接到任何方法一样。
How to push a view using a button in a navigation controller?
I tried to follow this example:
http://www.cimgf.com/2009/06/25/uitabbarcontroller-with-uinavigationcontroller-using-interface-builder/
This is exactly what I need, I have an UITabBarController
with 4 tabs and one of them is an UINavigationController
. I want to push that view containing the navigation controller from the first view- which is a simple UIView
. It doesn't work, I tried also with a programmatically created button and nothing happens. Any pointers?
Here's the code I have
@interface HomeViewController : UIViewController {
}
-(IBAction)pushViewController:(id)sender;
@end
---
#import "HomeViewController.h"
#import "NewViewController.h"
@implementation HomeViewController
-(IBAction)pushViewController:(id)sender {
NewViewController *controller = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
}
Here is also the screenshot with the connections
http://imageshack.us/photo/my-images/847/screenshot20110719at620.png/
I've tried what you guys suggested and still nothing, the buttons( whether they are created in Interface Builder
or programmatically ) act like they're not linked to any method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将其放在您要创建按钮的位置:(例如 Root VC 的
-viewDidLoad
)并实现此方法:
Put this where you want to create the button: (e.g. the Root VC's
-viewDidLoad
)And implement this method:
如果您使用 Storyboard,请手动创建 Segue
在 Storyboard 上:
,它将创建一个转场,现在选择转场并给它一个标识符
现在您可以使用代码:
现在您可以将操作连接到您的按钮
If you use storyboard, create a segue manually
On storyboard:
it will create a segue, now select the segue and give it a identifier
Now you can use the code:
now you can wire the action to your button
要将视图推送到导航控制器,只需执行以下操作:
现在,如果您希望按下按钮时发生这种情况,请向 nib 文件添加一个按钮,并将其连接到 Touch Up Inside 事件上的
IBAction
方法。To push a view to the navigation controller just do:
Now if you want it to happen when pressing a button, add a button to your nib file and connect it to a
IBAction
method on Touch Up Inside event.