-3

我尝试从一个视图控制器导航到另一个视图控制器以传递一个对象,我使用它

[self.navigationcontroller pushviewcontroller:VC2 animated : YES];

但没有用。请问我该怎么做

4

4 回答 4

2

尝试这个

在 App Delegate.m 中

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

在 View Controller.m 中

-(IBAction)buttonTapped:(id)sender{
   UIViewController vc2 = [[UIViewController alloc]initWithNibName:@"UCPAccuracyTableView" bundle:nil];
   [self.navigationController pushViewController:vc2 animated:YES];
   [vc2 release]; //if u r nt using ARC
}
于 2013-05-24T13:11:40.033 回答
2

如果要推送不是导航控制器的视图控制器,请使用以下代码

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
yourviewcontroller *cdvc = [storyboard instantiateViewControllerWithIdentifier:@"StoryboardIdentifierName Of the viewcontroller you have to push"];
[self.navigationController pushViewController:cdvc animated:YES];
于 2013-05-24T13:26:38.270 回答
0

在 Delegate.m 中,您需要初始化 Navigation 控制器。

RootViewController *rootController = [[RootViewController alloc] initWithNibName:@"Your nib name" bundle:nil];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootController];

[self.window setRootViewController:navigationController];

之后,您可以从一个控制器导航到另一个控制器。经过

[self.navigationcontroller pushviewcontroller:VC2 animated : YES];
于 2013-05-24T13:06:02.743 回答
0

制作导航控制器的对象然后推送

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];

[navController pushviewcontroller:VC2 animated : YES];
于 2013-05-24T13:06:36.103 回答