Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change view on button click in iPhone without navigation controller?

I want to know how to change view on button click in iPhone without navigation controller?

like image 657
user746909 Avatar asked Jan 31 '26 11:01

user746909


2 Answers

If you're doing this with a UIViewController, you would probably do this like following:

- (IBAction)change {
    UIViewController* viewController = [[UIViewController alloc] init];
    [self.view addSubView];
    // Save the UIViewController somewhere if necessary, otherwise release it
}

Not sure why you don't want to use a UINavigationController though. If it's the navigation bar at the top you don't want to see, there's a property for that so you can hide that bar. Not sure about it's name, probably navigationBarHidden or something like that. You can look that up in the API.

like image 199
pkoning Avatar answered Feb 03 '26 07:02

pkoning


There are many different ways you can do that, and you should possibly provide more information about your app.

A generic way to do it is the following, with animation:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];    
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

[vc1 viewWillDisappear:YES];
[vc2 viewWillAppear:YES];
vc1.view.hidden = YES;
vc2.view.hidden = NO;
[vc1 viewDidDisappear:YES];
[vc2 viewDidAppear:YES];

[UIView commitAnimations];

In this case, both views are there, you only hide/show them as you need. Alternatively, you could add/remove the view from their superview:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];    
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

[vc1 viewWillDisappear:YES];
[vc2 viewWillAppear:YES];
[vc1 removeFromSuperview];
[masterController.view addSubview:vc2.view;
[vc1 viewDidDisappear:YES];
[vc2 viewDidAppear:YES];

[UIView commitAnimations];
like image 27
sergio Avatar answered Feb 03 '26 05:02

sergio