我有两个 ViewController,一个名为 ViewController,另一个名为 Signup,
这是我用来调用 Signup.xib 文件的代码,
- (IBAction)signupButton:(id)sender {
Signup *myView = [[Signup alloc] initWithNibName:@"Signup" bundle:nil];
[self.view addSubview:myView.view];
}
此代码有效。它启动了 Signup Viewcontroller,但是当我尝试从 Signup.m 调用 ViewController.xib 文件时,它不起作用。
下面是我如何从 Signup.m 文件中调用 ViewController.xib 文件,
- (IBAction)loginView:(id)sender {
ViewController *dashboardView = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[self.view addSubview:dashboardView.view];
}
我已经在 Signup.m 文件中导入了 ViewController.h 文件。 loginView 按钮有效,因为我在按钮中放置了一个 NSLog() 以查看它是否有效并且确实如此。但是,当我单击 loginView 按钮时,出现了某种类型的错误。我不知道 xcode 中有什么错误,但它是这样的,
0x110309b: movl 8(%edx), %edi <- Thread 1: EXc_BAD_ACCESS (code=1, address=0x60000008)
它以绿色突出显示,我不知道它是什么意思。
最佳答案
正如用户 Priyatham51 所说,数字 3 是您收到错误的原因。如果您不使用 UINavigationController 来推送/弹出 View ,另一种方法是将 Signup View Controller 呈现为模态视图。然后当你想返回时,你可以在 Signup Controller 内部调用。
[self dismissModalViewControllerAnimated:YES];
但是您需要将注册按钮更改为。
- (IBAction)signupButton:(id)sender {
Signup *myView = [[Signup alloc] initWithNibName:@"Signup" bundle:nil];
[myView setModalPresentationStyle:UIModalPresentationFormSheet]; //you can change the way it is presented
[myView setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; //you can change the animation
[self presentModalViewController:myView animated:YES]; //show the modal view
}
希望对你有帮助
关于iphone - Viewcontroller 失败所以调用另一个 Viewcontroller - Objective-c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19031611/