在Xcode 4.3.2中将一个屏幕导航到另一个屏幕的问题?

时间:2012-09-06 06:14:13

标签: iphone xcode uinavigationcontroller push

目前我正在使用简单的iPhone应用程序,使用Xcode 4.3.2创建它,(不使用Storyboard)当我将一个屏幕导航到另一个屏幕时,发现错误:Thread1:EXC_BAD_ACCESS(code = 1.address = 0x7669739),同样地,我使用Story board将一个屏幕导航到另一个屏幕,它的工作正常。如何解决这个问题,请帮帮我

先谢谢

我尝试了这个(没有使用StoryBoard)

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"Screen 1";

    UIButton *btn =[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame=CGRectMake(10, 10, 200, 40);
    [btn setTitle:@"Test" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(GoToMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    // Do any additional setup after loading the view from its nib.
}

-(void)GoToMethod
{
    sample2 *s2 =[[sample2 alloc]init];
    [self.navigationController pushViewController:s2 animated:YES];
}

1 个答案:

答案 0 :(得分:0)

您可以从开发人员文档或搜索stackoverflow获得答案

 sample2 *s2 = [[sample2 alloc] initWithNibName:@"sample2" bundle:nil]; 
[self.navigationController pushViewController:s2 animated:YES];

您需要提及要加载的nib / xib名称。