Switching to another view controller without a navigation controller

As you might imagine, I'm still a beginner, getting my head off of developing iphone. I'm just trying to load a base load on request that I cannot get

I have an application with two view controllers, each view controller has connected a different nib file. I am trying to switch between the views manually; navigation control is not involved.

How can I manually switch the second view to the first view? self.navigationController pushViewControllerdoes not work because there is no navigation controller. How else can I click the second top view of the first view and destroy the first view; and, of course, vice versa? I did this on the first action of the browse button:

SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self.navigationController pushViewController:sv animated:YES];

obviously this did not work.

window addSubViewdoesn't work either, because the first view controller is the root view controller (not sure if I said it right). In other words, when I launch the application, the first view is what I see with the button, which should load the second view.

I spent hours searching for a simple example, and I could not find it.

Any suggestions?

+3
source share
3 answers

in the first view controller you need the following:

- (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 bind it to a button in nib. :)

+10
source

try:

SecondView *sv=[[SecondView alloc] initWithNibName:@"SecondView" bundle:nil];
[self presentModalViewController:sv animated:YES];
+8
source

xib, , appdelegate.m

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;

ViewController.m

- (IBAction)NextButtonClicked:(id)sender
{
    yourNextViewController *objyourNextViewController = [[yourNextViewController alloc] initWithNibName:@"yourNextViewController" bundle:nil];
    [self.navigationController pushViewController:objStartUpViewController animated:TRUE];
}
0

Source: https://habr.com/ru/post/1773798/


All Articles