简体   繁体   English

iOS / objective-c / xcode:在代码中实例化DetailView控制器

[英]IOS/objective-c/xcode: Instantiate DetailView Controller in Code

I had some code for launching a modal view controller created in storyboard with a storyboard ID. 我有一些代码用于启动在情节提要中创建的带有情节提要ID的模式视图控制器。 For a new situation, I am trying to adapt it to present a ViewController that is actually the detail view of a table in the main navigational system. 对于新情况,我正在尝试对其进行调整,以提供一个ViewController,它实际上是主导航系统中表格的详细视图。 I'm trying to jump around in the app if that is possible. 如果可能的话,我正在尝试在应用中跳来跳去。

In this case, the VC should not be modal. 在这种情况下,VC不应是模态的。 Instead, I want to take the user to the normal detail view of a table. 相反,我想将用户带到表的普通详细视图。

To make it more challenging, I need the detail view to have the object data. 为了使其更具挑战性,我需要局部视图具有对象数据。 Fortunately, this should be present in the starting VC. 幸运的是,这应该出现在起始VC中。

Here is my code for launching a modal VC. 这是我启动模式VC的代码。

 UIStoryboard *storyBoard = self.storyboard;
         detailVC *newVC =
         [storyBoard instantiateViewControllerWithIdentifier:@"detailView"];
         //pass object to new VC
         detailVC.object = _object;//pass data object
         UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: dareVC];
         [self presentModalViewController:nav animated:YES];

Edit: Following code does launch non-modal VC. 编辑:以下代码会启动非模式VC。 However, initial detail view is devoid of data. 但是,初始详细视图没有数据。 The data is saved so if I come back to it, the data is there but initially, I get generic screen with no data. 数据已保存,因此,如果我返回数据,就可以了,但是最初,我得到了没有数据的通用屏幕。

  detailVC *secondViewController =
         [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];
         [self.navigationController pushViewController:secondViewController animated:YES];
         secondViewController.object=_object;
  detailVC *secondViewController =
         [self.storyboard instantiateViewControllerWithIdentifier:@"detail"];
         secondViewController.object=_object;
         [self.navigationController pushViewController:secondViewController animated:YES];

First instantiate it. 首先实例化它。 Then set the data. 然后设置数据。 Then push it. 然后推。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM