在没有导航控制器的情况下导航到另一个视图控制器 [英] Navigating to another view controller without a navigation controller
问题描述
如你所说,我仍然是一个新手,让我的脑袋围绕iphone开发。
我只是尝试按需加载基本视图,我无法工作
As you guess am still a newbie, getting my head around iphone development. I am just trying out basic view loading on demand, which i cant get to work
我有一个应用程序,有2个视图控制器,每个视图控制器已连接一个不同的nib文件。
我试图手动切换视图;没有涉及导航控制。
I have an app, with 2 view controllers, each view controller connected a different nib file. I am trying to switch between view manually; there is no navigation control involved.
如何手动将第二个视图推送到第一个视图?
self.navigationController pushViewController
因为没有导航控制器而无法工作。
如何在第一个视图的顶部推送第二个视图并销毁第一个视图;和反之亦然?
我在第一个视图的按钮操作中完成了这个:
How can i manually push the second view to the first view?
self.navigationController pushViewController
wont work since there is no navigation controller.
How else can I push the second view on top of the first view and destroy the first view; and ofcourse vice versa?
I have done this in the first view's button action:
SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:sv animated:YES];
显然,它不起作用。
窗口addSubView
也不起作用,因为第一个视图控制器是根视图控制器(不确定我说的是正确的)。换句话说,当我运行应用程序时,第一个视图是我看到的一个按钮,它应该加载第二个视图。
window addSubView
didn't work either, because the first view controller is the root view controller (not sure i said that right). In other words, when i run the app, the first view is what I see with a button that is supposed to load the second view.
我花了几个小时搜索一个简单的例子,我找不到任何。
I have spent hours searching for a simple example, and I couldn't find any.
有什么建议吗?
推荐答案
在第一个视图控制器中你需要这个:
in the first view controller you need this:
- (IBAction)pushWithoutViewController:(id)selector {
NextNavigationController *page = [[NextNavigationController alloc] initWithNibName:NextNavigationController bundle:nil];
CGRect theFrame = page.view.frame;
theFrame.origin = CGPointMake(self.view.frame.size.width, 0);
page.view.frame = theFrame;
theFrame.origin = CGPointMake(0,0);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.8f];
page.view.frame = theFrame;
[UIView commitAnimations];
[self.view addSubview:page.view];
[page release];
}
然后将其链接到笔尖中的按钮。 :)
and then link it to the button in nib. :)
这篇关于在没有导航控制器的情况下导航到另一个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!