Aravindhan
Aravindhan

Reputation: 15628

navigate from one page to another in xcode

How can I navigate from one page to another page in xcode? remember without using the interface builder... I want the answer programmatically?

Upvotes: 0

Views: 8132

Answers (3)

Avinash651
Avinash651

Reputation: 1399

//Appdelegate.m

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}

//In viewcontroller1.M
- (IBAction)GoToNext:(id)sender 
{
ViewController2 *vc2 = [[ViewController2 alloc] init]; 
[self.navigationController pushViewController:vc2 animated:YES];
}

Upvotes: 0

devsri
devsri

Reputation: 6183

Although your question is not much clear but still I would like to give a try...

You can use

UIViewController *yourViewController = [[YourViewControllerClass alloc] initWithNibName:@"<name of xib>" bundle:nil];
[self presentModalViewController:yourViewController animated:YES];
[yourViewController release];

In case the new view is also to be created programmatically, you can do that in the viewDidLoad method of YourViewControllerClass and change the initialization to

UIViewController *yourViewController = [[YourViewControllerClass alloc] init];

In YourViewController when you wish to come back to previous view on some button action you can use

[self dismissModalViewControllerAnimated:YES];

Another way that you can do is

UIViewController *yourViewController = [[YourViewControllerClass alloc] init];
[self addSubview:[yourViewController view]];

and to remove the view you can use

[self.view removeFromSuperview];

Hope this works for you, if yes please communicate....:)

Upvotes: 1

visakh7
visakh7

Reputation: 26390

Pls be more precise if you want to get what you want.

If you are using view controllers within navigationcontroller you can make use of its pushViewController: or presentModalViewController:. Or if you just want to show another view you can just add the next view to existing view as subview.

Upvotes: 3

Related Questions