Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从代码中推送ViewController_Iphone_Ios_Uiviewcontroller - Fatal编程技术网

Iphone 从代码中推送ViewController

Iphone 从代码中推送ViewController,iphone,ios,uiviewcontroller,Iphone,Ios,Uiviewcontroller,在两个视图控制器之间切换时出现问题。我有一个名为myViewController的支持类。 我想单击主ViewController.m中的一个按钮并转到该视图 我在这个网站上找到了一些代码,但在我的代码中无法使用 ViewController.m #import "myViewController.h" -(void)viewDidLoad { //create button that will switch views UIButton *_buttonAccount = [UIBu

在两个视图控制器之间切换时出现问题。我有一个名为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];

}
试试这个

-(void) send:(id)sender
{

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

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

 }

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

用这个来介绍VC

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

    }] ;

类名(
myViewController
)和XIB(
myViewController
)名称不匹配。这并不是强制性的。但是,请检查您是否在init方法中传递了正确的XIB名称。我认为问题在于initWithNibName。您已编写为MyViewController,但它可能是MyViewController。检查一下。您确定正在加载的NIB是MyViewController吗?它区分大小写。请检查我的编辑answer@Andrea是否使用基于导航的类?请检查代码,按钮操作是通过
addTarget:action:forControlEvents:
method@Jitendra如果我们以编程方式将目标添加到按钮,那么就没有必要使用iAction。您也可以使用void。我更改了它以确保它显示“myViewController”,但它仍然给我错误“没有可见的@interface for myViewController”声明选择器“alloc”@Andrea F不使用myViewController作为实例名。你应该给它起个临时名字。否则会出错谢谢大家,更改实例名称是正确的。这段代码适用于任何想知道的人-(void)发送:(id)发送方{SignupView*SignupView=[[SignupView alloc]initWithNibName:@“myViewController”捆绑包:nil];[self-presentModalViewController:SignupView动画:是];}