xcode 6点击打开视图控制器

时间:2014-11-08 12:29:49

标签: ios xcode button viewcontroller

这是我的ViewController代码:

- (IBAction)click:(id)sender {
    twentysixViewController *detailScreen=[[twentysixViewController alloc]initWithNibName:@"twentysixViewController" bundle:[NSBundle mainBundle]];    
    [self.navigationController pushViewController:detailScreen animated:YES];
}

我也会在twentysixViewController中导入ViewController

#import "twentysixViewController.h"

这是twentysixViewController代码

#import "twentysixViewController.h"

@interface twentysixViewController ()

@end

@implementation twentysixViewController

   - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

但是当我点击ViewController中的按钮时,另一个twentysixViewController没有打开。我也用XIB文件创建twentysixViewController

1 个答案:

答案 0 :(得分:-1)

你为什么不使用segues?

您可以从主视图控制器到secondViewController创建一个segue。当该按钮点击时调用

[self performSegueWithIdentifier:@"segueIdentifier" sender:nil];

不要忘记使用您在界面构建器中指定的相应segue标识符更改segueIdentifier