正如你猜的那样,我还是个新手,正在了解 iPhone 开发。 我只是尝试按需加载基本 View ,但我无法开始工作
我有一个应用程序,有 2 个 View Controller ,每个 View Controller 连接一个不同的 nib 文件。 我正在尝试手动切换 View ;不涉及导航控制。
如何手动将第二个 View 推送到第一个 View ? self.navigationController PushViewController 将无法工作,因为没有导航 Controller 。 我还能如何将第二个 View 推到第一个 View 之上并销毁第一个 View ?当然反之亦然? 我在第一个 View 的按钮操作中完成了此操作:
SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:sv animated:YES];
显然,它不起作用。
window addSubView
也不起作用,因为第一个 View Controller 是 Root View Controller (不确定我说得对吗)。换句话说,当我运行应用程序时,第一个 View 是我通过应该加载第二个 View 的按钮看到的内容。
我花了几个小时寻找一个简单的例子,但没有找到。
有什么建议吗?
最佳答案
在第一个 View Controller 中你需要这个:
- (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];
}
然后将其链接到 Nib 中的按钮。 :)
关于iphone - 在没有导航 Controller 的情况下导航到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4132209/