开发者

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 program开发者_Go百科matically?


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.


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....:)


//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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜