2013-07-29 40 views
1

我想制作一个简单的导航控制应用程序,其中有两个视图控制器(ViewControllerViewController2)。我在ViewController中有一个按钮,当我按下按钮时,我想让它进入另一个视图。问题是该按钮不起作用。我也尝试过UIViewController,但是也没有这样做。在UINavigationController中,按钮无法与pushViewController一起使用

的AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 

    ViewController *vc1 = [[ViewController alloc]init]; 

    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc1]; 

    self.window.rootViewController = nav; 


    [self.window makeKeyAndVisible]; 
    [self.window addSubview:nav.view]; 
    return YES; 
} 

的ViewController.m

- (IBAction)myButton:(id)sender { 

    ViewController *vc2 = [[ViewController alloc]init]; 

    [[self navigationController]pushViewController:vc2 animated:YES]; 
} 

在此先感谢您的帮助

+0

您能更具体地了解它如何不起作用吗?什么都没有发生,或者当您按下按钮时应用程序崩溃? – Cezar

+0

当我按下按钮 – nahid

+0

时,没有任何反应您是否在* .xib文件中设置了“发送的事件”? – Starbax

回答

0

,如果你使用你的ViewController1的ViewController2故事板的进口,给故事板ID为“view2”:

ViewController2 *vc2 = (ViewController2 *)[self.storyboard instatiateViewControllerWithIdentifier:@"view2"]; 
    [self.navigationController pushViewController:vc2 animated:YES]; 
+0

我使用.xib文件,你能告诉我如何用.xib做到这一点吗? – nahid

+0

我不知道,但尝试:ViewController2 * vc2 = [[UIViewController alloc] initWithNibName:@“nameOfYourController”]; – Ilario

+0

感谢您的回复,但仍然无法正常工作 – nahid

相关问题