[英]How i can navigate from View Controller to another View Controller once clicking on button?
I am getting this exception when I am trying to move to another view:当我尝试移动到另一个视图时出现此异常:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'NextViewController''由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法加载包中的 NIB:“NSBundle(已加载)”,名称为“NextViewController”
NextViewController *temp = [[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
[self presentViewController:temp animated:YES comletion:nil];
Exception says that you don't have the NextViewController.xib file in your project. 异常表示您的项目中没有NextViewController.xib文件。 Double check whether you have it or not.
仔细检查您是否拥有它。
Also make sure you have given the NextViewController as your File's Owner Class of NextViewController.xib 另外,还要确保你已经给NextViewController为NextViewController.xib你的文件所有者类
Firstly, check if you really have NextViewController.xib ? 首先,检查一下你是否真的有NextViewController.xib ? If No, then how can you load your nib file?
如果否,那么如何加载你的nib文件? Also, check if you have NextViewController given as File's Owner class ?
另外,检查你是否将NextViewController作为File的Owner类提供 ?
If yes, 如是,
Check, if you used have navigationcontroller ? 检查,如果你使用了导航控制器 ? If yes, then change your code to :
如果是,请将您的代码更改为:
NextViewController *temp = [[NextViewController alloc]initWithNibName:@"NextViewController" bundle:nil];
[self.navigationcontroller presentViewController:temp animated:YES comletion:nil];
First you create uinavigationcontroller object first view set as a rootview controller after that set button on rootviewcontroller and push nextvie. 首先,在rootviewcontroller上的set按钮之后创建uinavigationcontroller对象第一个视图集作为rootview控制器并推送nextvie。
//for mainviewcontroller
UINavigationController *navigation =[[UINavigationController alloc]initWithRootViewController:viewcontroller];
[self.navigationController pushViewController:nextview animated:YES];
make sure you have the nib named NextViewController
on your project. 确保你的项目中有一个名为
NextViewController
的nib。 and also check if its added on your bundle resources. 并检查它是否添加到您的捆绑资源上。 see screenshot
看截图
If you are using swift 3.0,try below code 如果您使用的是swift 3.0,请尝试以下代码
//Here you can initiate your new ViewController
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "VadiveluPageViewController") as! VadiveluPageViewController
self.present(nextViewController, animated:true, completion:nil)
//if you need navigation controller use below
//self.navigationController?.pushViewController(nextViewController, animated: true)
Create 2 view controller in main story borad.在主故事板中创建 2 个视图控制器。 Go to main story board and select one view controller in main story board and drag and put into another view controller and select show method.
转到主故事板并在主故事板中选择一个视图控制器并将其拖放到另一个视图控制器中并选择显示方法。
Make sure to create class and identifer name in second View Controller.确保在第二个视图控制器中创建类和标识符名称。
Go to Editor option and select navigation method.转到编辑器选项并选择导航方法。 And put the below code in button action function.
并将以下代码放入按钮动作功能中。
self.performSegue(withIdentifer: "IdentiferName", sender: self)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.