我在 2 个视图控制器之间切换时遇到问题。我有一个名为 myViewController 的支持类。我想单击主 ViewController.m 中的一个按钮并转到此视图。
我查看了这个网站并找到了一些代码,但无法让它在我的代码中工作。
ViewController.m
#import "myViewController.h"
-(void)viewDidLoad
{ //create button that will switch views
UIButton *_buttonAccount = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[_buttonAccount setTitle:@"Create Account" forState:UIControlStateNormal];
_buttonAccount.frame = CGRectMake(110, 350, 95, 30);
[_buttonAccount addTarget:self action:@selector(send:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_buttonAccount];
}
-(void) send:(id)sender{
myViewController *myViewController = [[myViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
[self presentModalViewController:myViewController animated:YES];
[myViewController release];
}