iphone - 在没有导航 Controller 的情况下导航到另一个 View Controller

标签 iphone view

正如你猜的那样,我还是个新手,正在了解 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/

相关文章:

iphone - 带参数的选择器

database - MVC4如何获取外键代表的值

ios - map View 不关注注释

javascript - 我希望我的 View 获取属性的值

iphone - 找到 NSString 的正确宽度

iPhone 应用程序在 appStore 中可用的语言

ios - 将应用程序更新到 iOS 7 时,奇怪的 Storyboard会推送 segue。

ios - 一次关闭所有 View Controller

java - 使用 hibernate 从数据库获取数据时如何过滤数据?

xcode - Xcode StoryboardSegue循环回到同一 View