在xcode中从一个页面导航到另一个页面

时间:2011-03-21 08:58:40

标签: iphone objective-c xcode

如何在xcode中从一个页面导航到另一个页面?记得没有使用界面构建器...我想以编程方式获得答案吗?

3 个答案:

答案 0 :(得分:3)

如果你想得到你想要的东西,请更准确。

如果您在navigationcontroller中使用视图控制器,则可以使用其pushViewController:presentModalViewController:。或者,如果您只想显示另一个视图,则只需将下一个视图添加到现有视图作为子视图。

答案 1 :(得分:1)

虽然你的问题不太清楚,但我仍想尝试一下......

您可以使用

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

如果还要以编程方式创建新视图,可以在YourViewControllerClass的viewDidLoad方法中执行此操作,并将初始化更改为

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

在YouViewController中,如果您希望返回某个按钮操作的上一个视图,可以使用

[self dismissModalViewControllerAnimated:YES];

你可以做的另一种方法是

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

并删除您可以使用的视图

[self.view removeFromSuperview];

希望这对你有用,如果是,请沟通.... :)

答案 2 :(得分:0)

// 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];
}
相关问题