0

我在 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];

}
4

2 回答 2

0

Use this to present the VC

[self presentViewController: myViewController animated:YES completion:^{

    }] ;
于 2013-05-29T13:38:14.223 回答
0

试试这个

-(void) send:(id)sender
{

        myViewController *myViewController = [[myViewController alloc] initWithNibName:@"MyViewController" bundle:nil];

        [self.navigationController pushViewController:passview animated:NO];

 }

试试这个对你真的很有帮助。

于 2013-05-29T13:17:28.777 回答