• <small id='8eq4k'></small><noframes id='8eq4k'>

    <legend id='8eq4k'><style id='8eq4k'><dir id='8eq4k'><q id='8eq4k'></q></dir></style></legend>

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

        • <bdo id='8eq4k'></bdo><ul id='8eq4k'></ul>
      1. 在视图控制器之间传递数据/对象/moc - 最佳实践

        时间:2023-06-12
        <legend id='mU0KT'><style id='mU0KT'><dir id='mU0KT'><q id='mU0KT'></q></dir></style></legend>
      2. <i id='mU0KT'><tr id='mU0KT'><dt id='mU0KT'><q id='mU0KT'><span id='mU0KT'><b id='mU0KT'><form id='mU0KT'><ins id='mU0KT'></ins><ul id='mU0KT'></ul><sub id='mU0KT'></sub></form><legend id='mU0KT'></legend><bdo id='mU0KT'><pre id='mU0KT'><center id='mU0KT'></center></pre></bdo></b><th id='mU0KT'></th></span></q></dt></tr></i><div id='mU0KT'><tfoot id='mU0KT'></tfoot><dl id='mU0KT'><fieldset id='mU0KT'></fieldset></dl></div>

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

              1. <small id='mU0KT'></small><noframes id='mU0KT'>

                <tfoot id='mU0KT'></tfoot>

                    <tbody id='mU0KT'></tbody>

                  本文介绍了在视图控制器之间传递数据/对象/moc - 最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个我怀疑很常见的场景,我在回答其他类似问题时发现了各种想法,包括设置 IBOutlets、将 NSmanagedobjects 作为属性传递以及只使用一个视图控制器但换出视图,但我不确定哪个是为我的解决方案实施的最佳想法.

                  I have a scenario that i suspect is very common, i've found various ideas in responses to other similar questions including setting up IBOutlets, passing NSmanagedobjects as properties and just using one view controller but swapping out the views but I'm uncertain as to which would be the best idea to implement for my solution.

                  我有一个具有典型模型的 iOS/iphone 应用程序.UITabBarController 包含多个 UINavigationControllers.

                  I have an iOS/iphone app that has a typical model. UITabBarController containing multiple UINavigationControllers.

                  在其中一个导航控制器中,我有一个带有 tableView 的视图控制器.这个 tableView 是从获取的核心数据实体中填充的,称为标签".当我使用 UIBarButtonItem (Add) 设置 tableView 时,添加按钮的行为如下:我需要它为该实体创建一个新的标签"对象,并用一些已知数据填充该对象,然后提示用户钻取向下 3 级分类(区域 -> 区域 -> 主题)到达一个主题对象.然后我需要将该主题"对象添加到原始新添加的标签"对象的关系中(堆栈下方的 3 个视图).- 希望这很清楚.

                  In one of the navigation controllers i have a viewcontroller with a tableView in it. This tableView is populated from fetched core Data entity is called 'tags'. When I set the tableView up with a UIBarButtonItem (Add) the add button needs to behave as follows: I need it to create a new 'tag' object for that entity and populate the object with some known data and then prompt the user to drill down 3 levels of classification (Region -> area -> topic) to reach a topic object. i then need to add that 'topic' object to a relationship of the original newly added 'tag' object (3 views further down the stack). - hope thats clear.

                  (有很多代码我不确定要呈现哪些位,所以我现在用主要代码段来描述,一定要让我知道你想看到的任何具体代码.)

                  (there's lots of code I'm not sure which bits to present so i'm describing for now with the main snippet, by all means let me know any specific code you'd like to see.)

                  - (void)addTag {    
                  
                  NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
                  NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
                  NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
                  [newManagedObject setValue:@"(untitled)" forKey:@"tagID"];
                  
                  NSError *error;
                  if (![context save:&error])
                      NSLog(@"Error saving entity: %@", [error localizedDescription]);
                  
                  
                  ChooseRegion *aView = [[[ChooseRegion alloc] init] autorelease];
                  aView.theTag = newManagedObject;
                  
                  [self.navigationController pushViewController:aView animated:YES];
                  
                  }
                  

                  您可以看到我已经创建了对象,将其中一个属性设置为值,保存并将对象传递给下一个视图(chooseRegion),这是 3 个视图中的第一个.在每个 didSelectRowAtIndexPath 代码上,将选定的行和这个标记"对象传递给下一个视图,我不确定这是否正确,因为我不确定当我到达第三个视图的主题对象时该怎么做???我迷路了.

                  You can see I've created the object, set one of it's properties a value, saved it and passed the object to the next view (chooseRegion) which is the first of 3 views. on each the didSelectRowAtIndexPath code passes the selected row and this 'tag' object to the next view, i'm not sure whether this is right because i'm not sure what to do when i get to the topic object on the 3rd view??? i'm lost.

                  给猫剥皮总是不止一种方法,但我应该从什么方法来解决这个问题.我应该将标签"对象向前传递并将其保存在第三个视图中,还是将所选主题传回并将其保存在创建标签"对象的原始视图中?

                  Always more than one way to skin a cat but what approach should i be tackling this from. Should I be passing the 'tag' object forward and save it at the 3rd view or pass back the selected topic and save it at the original view which created the 'tag' object?

                  非常感谢.

                  推荐答案

                  我会为此使用通知.通知是一种将应用程序的各个部分解耦的简单方法,但它们仍然可以协同工作.

                  I would use notifications for this. Notifications are a simple way to decouple parts of the application, but still have them work together.

                  在您的情况下,当用户在第三个视图中选择标签对象时,我会发送这样的通知:

                  In your case, the moment the user selects the tag object in the 3rd view, I would send a notification as such:

                  [[NSNotificationCenter defaultCenter] postNotificationName:@"tagSelected" object:myTag];
                  

                  现在,在具有添加"按钮的控制器中,使其订阅该事件:

                  Now, in the controller that has the "add" button, make it subscribe to that event:

                  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTagSelected:) name:@"tagSelected" object:nil];
                  

                  确保你实现了 handleTagSelected: 方法,并且在该方法中你可以获取标签对象并关闭你打开的向下钻取视图:

                  Make sure you implement the handleTagSelected: method, and in that method you can get the tag object and close the drilldown view that you have open:

                  - (void)handleTagSelected:(NSNotification *)notification {
                      Tag *mytag = (Tag *)notification.object;
                      [self dismissModalViewControllerAnimated:YES];
                  }
                  

                  然后你可以对标签做任何你想做的事情.

                  Then you can do whatever you want with the tag.

                  这篇关于在视图控制器之间传递数据/对象/moc - 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:选项卡式导航视图的正确设计模式? 下一篇:如何在 UINavigationController 的 RootViewController 上显示返回按钮?

                  相关文章

                    <bdo id='6kyK2'></bdo><ul id='6kyK2'></ul>
                1. <small id='6kyK2'></small><noframes id='6kyK2'>

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