[英]How do I switch a new view controller in iOS development?
我正在尝试编写一个IBAction来切换我的iPhone应用程序的视图控制器:
-(IBAction)changeToView2:(id)sender
{
if (self.view2 == nil)
{
view2 = [[UIViewController alloc] initWithNibName:@"View2Controller" bundle:[NSBundle mainBundle]];
}
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentedViewController: view2 animated:YES];
}
但是,我收到一个构建错误,指出没有接口声明“presentViewController:animated:”。 为什么?
将其更改为“presentViewController:animated:”会产生相同的错误。
方法是presentViewController:animated:completion:
, not present
ed ViewController:animated:
代替
[self presentedViewController: view2 animated:YES];
尝试
[self presentViewController: view2 animated:YES];
[self presentViewController:view2 animated:YES];
试试这个你编辑过的代码。我想这会对你有所帮助。
-(IBAction)changeToView2:(id)sender
{
if (self.view2 == nil)
{
view2 = [[UIViewController alloc] initWithNibName:@"View2Controller" bundle:nil];
}
self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentedViewController: view2 animated:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.