在没有导航控制器的情况下导航到另一个视图控制器

Vee*_*eru 3 iphone views

如你所想,我仍然是一个新手,让我的脑袋围绕iphone开发.我只是尝试按需加载基本视图,我无法开始工作

我有一个应用程序,有2个视图控制器,每个视图控制器连接一个不同的nib文件.我想手动切换视图; 没有涉及导航控制.

如何手动将第二个视图推送到第一个视图? self.navigationController pushViewController因为没有导航控制器所以不能工作.如何在第一个视图的顶部推动第二个视图并销毁第一个视图; 和反之亦然?我在第一个视图的按钮操作中完成了这个操作:

SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:sv animated:YES];
Run Code Online (Sandbox Code Playgroud)

显然,它没有用.

window addSubView也没有工作,因为第一个视图控制器是根视图控制器(不确定我说的是正确的).换句话说,当我运行应用程序时,第一个视图就是我看到的一个按钮,它应该加载第二个视图.

我花了几个小时寻找一个简单的例子,我找不到任何一个.

有什么建议?

Tho*_*son 10

在第一个视图控制器中,您需要这个:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

然后将其链接到笔尖中的按钮.:)


Gya*_*ani 8

尝试:

SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self presentModalViewController:sv animated:YES];
Run Code Online (Sandbox Code Playgroud)

  • @Veeru是的,可以添加不同类型的动画,例如SecondView*sv = [[SecondView alloc] initWithNibName:@"SecondView"bundle:nil]; sv.modalTransitionStyle = UIModalTransitionStyleFlipHorizo​​ntal; [self presentModalViewController:sv animated:YES]; (2认同)