• <tfoot id='e77zy'></tfoot>
    <legend id='e77zy'><style id='e77zy'><dir id='e77zy'><q id='e77zy'></q></dir></style></legend>
    <i id='e77zy'><tr id='e77zy'><dt id='e77zy'><q id='e77zy'><span id='e77zy'><b id='e77zy'><form id='e77zy'><ins id='e77zy'></ins><ul id='e77zy'></ul><sub id='e77zy'></sub></form><legend id='e77zy'></legend><bdo id='e77zy'><pre id='e77zy'><center id='e77zy'></center></pre></bdo></b><th id='e77zy'></th></span></q></dt></tr></i><div id='e77zy'><tfoot id='e77zy'></tfoot><dl id='e77zy'><fieldset id='e77zy'></fieldset></dl></div>
      <bdo id='e77zy'></bdo><ul id='e77zy'></ul>
    1. <small id='e77zy'></small><noframes id='e77zy'>

        通过视图控制器、标签栏控制器、导航控制器和视图控制器传递数据

        时间:2023-06-12
          <tbody id='WNmJf'></tbody>

        <small id='WNmJf'></small><noframes id='WNmJf'>

            <bdo id='WNmJf'></bdo><ul id='WNmJf'></ul>

            <legend id='WNmJf'><style id='WNmJf'><dir id='WNmJf'><q id='WNmJf'></q></dir></style></legend>
            • <i id='WNmJf'><tr id='WNmJf'><dt id='WNmJf'><q id='WNmJf'><span id='WNmJf'><b id='WNmJf'><form id='WNmJf'><ins id='WNmJf'></ins><ul id='WNmJf'></ul><sub id='WNmJf'></sub></form><legend id='WNmJf'></legend><bdo id='WNmJf'><pre id='WNmJf'><center id='WNmJf'></center></pre></bdo></b><th id='WNmJf'></th></span></q></dt></tr></i><div id='WNmJf'><tfoot id='WNmJf'></tfoot><dl id='WNmJf'><fieldset id='WNmJf'></fieldset></dl></div>
                <tfoot id='WNmJf'></tfoot>

                  本文介绍了通过视图控制器、标签栏控制器、导航控制器和视图控制器传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  这可能很容易实现,但我是 iOS 编程新手,我似乎被卡住了.

                  This is probably something really simple to achieve, but I am new to programming for iOS and I seem to be stuck.

                  所以,基本上,我有一个选项卡式应用程序.我决定除了标签栏之外还需要一个导航栏.为此,我放置了标签栏控制器,然后添加了我的视图控制器并嵌入到每个视图控制器的导航控制器中,然后将其连接到标签栏.

                  So, basically, I have a tabbed application. I decided that I wanted a navigation bar, in addition to the tab bar. To do this, I put the tab bar controller and then I added my view controllers and embedded in a navigation controller for each view controller, which is then connected to the tab bar.

                  我在故事板中的层次结构有点像这样:

                  My hierarchy in the storyboard looks somewhat like this:

                  1. 视图控制器
                  1. 标签栏控制器
                  1. 导航控制器
                  1. 视图控制器

                1. 导航控制器

                2. Navigation Controller

                  1. 视图控制器

                3. 我被困在这里的部分是尝试将数据从第一个 View Controller 传递到任何其他 View Controller 时.在添加导航控制器之前,我使用 prepareForSegue 方法来传递数据,如下所示:

                  The part where I am stuck here, is when attempting to pass data from the first View Controller and to any of the other View Controllers. Before adding in the navigation controllers, I was using the prepareForSegue method to pass the data, like so:

                  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
                  {
                      if ([[segue identifier] isEqualToString:@"logged"])
                      {
                          UITabBarController *tabar=segue.destinationViewController;
                          SecondViewController *svc=[tabar.viewControllers objectAtIndex:1];
                          svc.groupArray = [(NSArray*)sender objectAtIndex:0];
                          svc.userArray = [(NSArray*)sender objectAtIndex:1];
                          svc.taskArray = [(NSMutableArray*)sender objectAtIndex:2];
                          svc.selfArray = [(NSMutableArray*)sender objectAtIndex:3];
                          [tabar setSelectedIndex:1];
                      }
                  }
                  

                  如您所见,我将数据传递给我的第二个视图控制器并使用 performSegueWithIdentifier 方法将标签栏索引设置为 1,因为我希望打开第二个页面.所有这一切都工作得很好,直到我将导航控制器引入我的代码,因为我想要导航栏.那时一切都崩溃了.如果我尝试按原样运行代码,应用程序会崩溃并在控制台中显示以下输出:

                  As you can see, I was passing the data to my second view controller and set the tab bar index to 1 using the performSegueWithIdentifier method, since I wanted the second page to open. All of this was working just fine, until I introduced the Navigation Controllers to my code, since I want navigation bars. That's when everything pretty much broke. If I try to run the code as is, the application crashes with the following output in the console:

                  [UINavigationController setGroupArray:]: 无法识别的选择器发送到实例 0x7ffa6acec620

                  [UINavigationController setGroupArray:]: unrecognized selector sent to instance 0x7ffa6acec620

                  *** 由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'-[UINavigationController setGroupArray:]: unrecognized selector sent to instance 0x7ffa6acec620'

                  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setGroupArray:]: unrecognized selector sent to instance 0x7ffa6acec620'

                  我尝试过修改代码,但似乎没有任何效果.我只是很困惑,也许正确方向的提示会对我有所帮助.

                  I've tried messing around with the code a bit, but nothing seems to work really. I am just very confused, and maybe a hint in the right direction would help me out a bit.

                  推荐答案

                  由于您将视图控制器嵌入到导航控制器中,它们不再是标签栏的直接子级;但是,您将标签栏控制器的子级转换为导航控制器以外的其他东西.您想首先获取导航控制器,它是标签栏控制器的子级,然后获取该导航控制器的子级.这将是您的视图控制器.然后,您可以为此设置数据.

                  Since you embedded your view controllers inside navigation controllers they are no longer direct children of the tabbar; however, you are casting the children of the tabbar controller as something other than Navigation controllers. You want to first get the navigation controller, which is a child of the tabbar controller, and then get the child of that navigation controller. This will be your view controller. Then you can set the data for that.

                  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
                  {
                      if ([[segue identifier] isEqualToString:@"logged"])
                     {
                         UITabBarController *tabar=segue.destinationViewController;
                         UINavigationController *navController = [tabbar.viewControllers objectAtIndex:1];
                         SecondViewController *svc=[navController.viewControllers objectAtIndex:0];
                         svc.groupArray = [(NSArray*)sender objectAtIndex:0];
                         svc.userArray = [(NSArray*)sender objectAtIndex:1];
                         svc.taskArray = [(NSMutableArray*)sender objectAtIndex:2];
                         svc.selfArray = [(NSMutableArray*)sender objectAtIndex:3];
                         [tabar setSelectedIndex:1];
                     }
                  }
                  

                  这篇关于通过视图控制器、标签栏控制器、导航控制器和视图控制器传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何让导航栏后退按钮返回到另一个视图控制器 下一篇:iOS 暗淡背景 查看全屏

                  相关文章

                  <tfoot id='jVegY'></tfoot>

                    <i id='jVegY'><tr id='jVegY'><dt id='jVegY'><q id='jVegY'><span id='jVegY'><b id='jVegY'><form id='jVegY'><ins id='jVegY'></ins><ul id='jVegY'></ul><sub id='jVegY'></sub></form><legend id='jVegY'></legend><bdo id='jVegY'><pre id='jVegY'><center id='jVegY'></center></pre></bdo></b><th id='jVegY'></th></span></q></dt></tr></i><div id='jVegY'><tfoot id='jVegY'></tfoot><dl id='jVegY'><fieldset id='jVegY'></fieldset></dl></div>

                      <small id='jVegY'></small><noframes id='jVegY'>

                    1. <legend id='jVegY'><style id='jVegY'><dir id='jVegY'><q id='jVegY'></q></dir></style></legend>

                      • <bdo id='jVegY'></bdo><ul id='jVegY'></ul>