简体   繁体   English

单击按钮后,如何从视图控制器导航到另一个视图控制器?

[英]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 另外,还要确保你已经给NextViewControllerNextViewController.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.

相关问题 如何从一个视图控制器导航到另一视图控制器? - How to navigate from one view controller to another view controller? iOS无法从表视图控制器导航到另一个 - IOS can't navigate from a table view controller to another one 如何在推送通知中导航到另一个视图控制器 - How to navigate to another view controller in push notifications 如何从一个视图控制器导航到另一个 - How to navigate From one view controller to other 单击第一个视图控制器中的按钮时如何通过选项卡栏控制器从一个视图控制器转到另一个视图控制器 - How to go from one view controller to another view controller through tab bar controller when Click a button in the first view controller 加载外部视图控制器,通过按钮单击另一个视图控制器 - Loading an external view controller, from a button click on another view controller 在另一个视图控制器中单击删除按钮后,如何在表格视图中删除单元格数据并重新排列 - how to delete a cell data in a table view and rearranging after clicking the delete button in another view controller iPhone:如何从另一个控制器类访问View控制器类中的数据? - iPhone: How I can Access Data in a View Controller Class from Another Controller Class? 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller? 我可以从另一个模态视图控制器中推送模态视图控制器吗? - Can I push a modal view controller from within another modal view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM