pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <legend id='uEDX3'><style id='uEDX3'><dir id='uEDX3'><q id='uEDX3'></q></dir></style></legend>

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

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

        試圖在視圖控制器之間傳遞數(shù)據(jù)

        Trying to pass data between viewControllers(試圖在視圖控制器之間傳遞數(shù)據(jù))

          <tbody id='AEOFk'></tbody>
        <i id='AEOFk'><tr id='AEOFk'><dt id='AEOFk'><q id='AEOFk'><span id='AEOFk'><b id='AEOFk'><form id='AEOFk'><ins id='AEOFk'></ins><ul id='AEOFk'></ul><sub id='AEOFk'></sub></form><legend id='AEOFk'></legend><bdo id='AEOFk'><pre id='AEOFk'><center id='AEOFk'></center></pre></bdo></b><th id='AEOFk'></th></span></q></dt></tr></i><div class="lwgymvq" id='AEOFk'><tfoot id='AEOFk'></tfoot><dl id='AEOFk'><fieldset id='AEOFk'></fieldset></dl></div>
          <legend id='AEOFk'><style id='AEOFk'><dir id='AEOFk'><q id='AEOFk'></q></dir></style></legend>
          • <small id='AEOFk'></small><noframes id='AEOFk'>

                  <bdo id='AEOFk'></bdo><ul id='AEOFk'></ul>
                  <tfoot id='AEOFk'></tfoot>
                  本文介紹了試圖在視圖控制器之間傳遞數(shù)據(jù)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我在 NavigationController 中有一系列 4 個視圖控制器,每個視圖控制器都從用戶那里獲取一些文本字段,這些文本字段存儲在 NSMutableDictionary 中.

                  I have a sequence of 4 viewControllers inside a NavigationController, each grabs a few textFields of input from the user which are stored in a NSMutableDictionary.

                  每個 VC 的集合在 segue 之前都將自己作為 nextVC 的代表,它還傳遞 NSMutDict.

                  Each of the VC's set's itself up as the delegate of the nextVC before it segues, it also passes the NSMutDict along.

                  這很好用.

                  我不明白的是:

                  假設我已經(jīng)填寫了 VC1 中的 5 個文本字段.然后我將自己設置為 VC2 的代表,將帶有輸入數(shù)據(jù)的字典傳遞給 VC2,然后轉(zhuǎn)到 VC2.在 VC2 中,我填寫了另外 4 個文本字段并將它們添加到字典中.如果我決定需要更改 VC1 中的某些內(nèi)容,我會點擊后退按鈕并修改數(shù)據(jù).但是當我再次前進時,我丟失了我在 VC2 上輸入的內(nèi)容.

                  Say I have filled in the 5 textFields in VC1. Then I set myself as the delegate of VC2, pass VC2 the dictionary with the input data and segue to VC2. In VC2 I fill in another 4 textFields and add these to the dictionary. If I then decide I need to change something in VC1 I tap the back button and amend the data. But when I go forwards again I lose the stuff I input on VC2.

                  如何將字典與添加的信息一起傳遞回 VC1,以便當它再次轉(zhuǎn)發(fā)到 VC2 時它包含所有內(nèi)容?

                  How do I pass the dictionary back to VC1 with the added info so that when it gets passed forwards to VC2 again it has everything in it?

                  委托 (VC1) 有一個方法可以用 VC2 中的字典更新其字典.

                  The delegate (VC1) has a method to update its dictionary with the dictionary in VC2.

                  我還自定義了 VC2 中的 backBarButtonItem,方法是在 VC1 的 prepareForSegue: 方法中設置它.

                  I have also customised the backBarButtonItem in VC2 by setting it in the prepareForSegue: method in VC1.

                  我想我已經(jīng)接近了,但是......

                  I think I'm getting close but...

                  我只能通過在 VC2 中設置 leftBarButtonItem 并使用它而不是默認的后退按鈕來使目標操作起作用.

                  I can only get the target actions to work by setting a leftBarButtonItem in VC2 and using that instead of the default back button.

                  在 VC1 (prepareForSegue:) 中設置后退按鈕似乎不允許設置任何目標或操作.

                  Setting the back button in VC1 (prepareForSegue:) doesn't seem to allow any target or action to be set.

                  我知道我無法在 VC2 中設置后退按鈕,我該怎么辦?我可以使用委托從 VC2 設置后退按鈕的目標和操作嗎?

                  I know I can't set the back button in VC2, so what can I do? Can I set the target and action of the back button from VC2 using the delegate?

                  我認為這可能與 UINavigationBarDelegate 有關,但我不知道該放在哪里.我嘗試在 VC2 中設置它,但它沒有做任何事情.

                  I think it may be something to do with UINavigationBarDelegate but I can't figure out where to put what with that. I tried setting it up in VC2 but it didn't do anything.

                  TIA.

                  以下是相關代碼:

                  協(xié)議:

                  #import <Foundation/Foundation.h>
                  
                  @protocol IAXAddNewUserDelegate <NSObject>
                  @required
                  - (void)updateNewUserDataWithData: (NSMutableDictionary *)newData;
                  
                  @end
                  

                  來自 VC1.h:

                  #import "IAXAddNewUserDelegate.h"
                  
                  @interface IAXAddNewUser1 : UITableViewController <UITextFieldDelegate, UIAlertViewDelegate, IAXAddNewUserDelegate>
                  
                  @property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
                  @property (strong, nonatomic) User *selectedUser;
                  @property (strong, nonatomic) User *aNewUser;
                  @property BOOL isFirstUser;
                  
                  - (void)updateNewUserDataWithData: (NSMutableDictionary *)newData;
                  
                  @end
                  

                  來自 VC1.m:

                  #pragma mark - Segues
                  - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
                  {
                      if ([segue.identifier isEqualToString:@"AddUser2"]) {
                          IAXAddNewUser2 *addUser2VC = segue.destinationViewController;
                          addUser2VC.managedObjectContext = self.managedObjectContext;
                          addUser2VC.progressTotal = self.progressTotal;
                          addUser2VC.isFirstUser = self.isFirstUser;
                          addUser2VC.userData = self.userData;
                          addUser2VC.delegate = self;
                          if (self.selectedUser) {
                              addUser2VC.selectedUser = self.selectedUser;
                          }
                          self.title = @"Step 1";
                          UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" 
                                                                                         style:UIBarButtonItemStyleBordered 
                                                                                        target:self 
                                                                                        action:@selector(passDataBack:)];
                          self.navigationItem.backBarButtonItem = backButton;
                      }
                  }
                  
                  #pragma mark - IAXAddNewUserDelegate Methods
                  - (void)updateNewUserDataWithData: (NSMutableDictionary *)newData
                  {
                      self.userData = newData;
                      NSLog(@"Updated AddUserVC1");
                  }
                  

                  來自 VC2.m

                  -(void)passDataBack:(id)sender
                  {
                      NSLog(@"Sending Data Back to VC1");
                      [self.delegate updateNewUserDataWithData:self.userData];
                      [self.navigationController popViewControllerAnimated:YES];
                  }
                  

                  推薦答案

                  如果您要更新所有其他詞典中的所有詞典,請嘗試使用單例.您可以在此處查看示例:https://stackoverflow.com/a/9690731/542400

                  If you're updating all the dictionaries from all the other dictionaries, try using a singleton. You can see an example here: https://stackoverflow.com/a/9690731/542400

                  另外,這里有一些代碼:

                  Also, here's some code:

                  MainDictionary.h

                  MainDictionary.h

                  @interface MainDictionary : NSObject{
                      NSMutableDictionary *dictionary;
                  }
                  
                  +(MainDictionary *)sharedDictionary;
                  -(NSString *)getStringForKey:(NSString *)string;
                  -(void)setString:(NSString *)string forKey:(NSString *)key;
                  @end
                  

                  MainDictionary.m

                  MainDictionary.m

                  #import "MainDictionary.h"
                  
                  static MainDictionary *sharedDictionary;
                  
                  @implementation MainDictionary
                  
                  -(id)init{
                      self = [super init];
                      dictionary = [[NSMutableDictionary alloc] init];
                      // if you want to add anything preliminary to the dictionary, do it here
                      return self;
                  }
                  
                  +(MainDictionary *)sharedDictionary{
                      static dispatch_once_t onceToken;
                      dispatch_once(&onceToken, ^{
                      sharedDictionary = [[self alloc] init];
                      });
                  return sharedDictionary;
                  }
                  -(NSString *)getStringForKey:(NSString *)string{
                      return [dictionary objectForKey:string];
                  }
                  -(void)setString:(NSString *)string forKey:(NSString *)key{
                      [dictionary setValue:string forKey:key];
                  }
                  @end
                  

                  現(xiàn)在#import MainDictionary.h,只要您想訪問或設置該字典中的值(在本例中,當您的文本字段結(jié)束編輯時),只需執(zhí)行以下操作:

                  Now #import MainDictionary.h, and any time you want to access or set values in that dictionary (in this example, when your textFields end editing), just do this:

                  -(void)textFieldDidEndEditing:(UITextField *)textField{
                      if(textField == textField1){
                          [[MainDictionary sharedDictionary] setString: textField.text forKey:@"textField1"];
                      }
                  }
                  

                  或:

                  -(void)viewWillAppear{
                      textField1.text = [[MainDictionary sharedDictionary] getStringForKey:@"textField1"];
                      [super viewWillAppear:YES];
                  }
                  

                  在每個 VC 中實現(xiàn)這一點,你就可以開始了.

                  Implement this in each VC, and you're good to go.

                  這篇關于試圖在視圖控制器之間傳遞數(shù)據(jù)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to animate a UIImageview to display fullscreen by tapping on it?(如何通過點擊動畫 UIImageview 以顯示全屏?)
                  To stop segue and show alert(停止 segue 并顯示警報)
                  iOS 5 storyboard, programmatically determine path(iOS 5 故事板,以編程方式確定路徑)
                  Icon already includes gloss effects(圖標已經(jīng)包含光澤效果)
                  How does UIEdgeInsetsMake work?(UIEdgeInsetsMake 是如何工作的?)
                  UIProgressView and Custom Track and Progress Images (iOS 5 properties)(UIProgressView 和自定義跟蹤和進度圖像(iOS 5 屬性))
                  <i id='AmmRo'><tr id='AmmRo'><dt id='AmmRo'><q id='AmmRo'><span id='AmmRo'><b id='AmmRo'><form id='AmmRo'><ins id='AmmRo'></ins><ul id='AmmRo'></ul><sub id='AmmRo'></sub></form><legend id='AmmRo'></legend><bdo id='AmmRo'><pre id='AmmRo'><center id='AmmRo'></center></pre></bdo></b><th id='AmmRo'></th></span></q></dt></tr></i><div class="iyeoyt3" id='AmmRo'><tfoot id='AmmRo'></tfoot><dl id='AmmRo'><fieldset id='AmmRo'></fieldset></dl></div>
                • <tfoot id='AmmRo'></tfoot>

                • <legend id='AmmRo'><style id='AmmRo'><dir id='AmmRo'><q id='AmmRo'></q></dir></style></legend>
                    <tbody id='AmmRo'></tbody>
                  • <small id='AmmRo'></small><noframes id='AmmRo'>

                      <bdo id='AmmRo'></bdo><ul id='AmmRo'></ul>
                            主站蜘蛛池模板: 污水处理设备-海普欧环保集团有限公司 | 塑料脸盆批发,塑料盆生产厂家,临沂塑料广告盆,临沂家用塑料盆-临沂市永顺塑业 | 牛皮纸|牛卡纸|进口牛皮纸|食品级牛皮纸|牛皮纸厂家-伽立实业 | 船用泵,船用离心泵,船用喷射泵,泰州隆华船舶设备有限公司 | 上海小程序开发-上海小程序制作公司-上海网站建设-公众号开发运营-软件外包公司-咏熠科技 | 长城人品牌官网| 玉米深加工设备|玉米加工机械|玉米加工设备|玉米深加工机械-河南成立粮油机械有限公司 | 电动葫芦|防爆钢丝绳电动葫芦|手拉葫芦-保定大力起重葫芦有限公司 | 深圳网站建设-高端企业网站开发-定制网页设计制作公司 | 高精度-恒温冷水机-螺杆式冰水机-蒸发冷冷水机-北京蓝海神骏科技有限公司 | led全彩屏-室内|学校|展厅|p3|户外|会议室|圆柱|p2.5LED显示屏-LED显示屏价格-LED互动地砖屏_蕙宇屏科技 | 丹佛斯变频器-丹佛斯压力开关-变送器-广州市风华机电设备有限公司 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 购买舔盐、舔砖、矿物质盐压块机,鱼饵、鱼饲料压块机--请到杜甫机械 | 阻燃剂-氢氧化镁-氢氧化铝-沥青阻燃剂-合肥皖燃新材料 | 户外-组合-幼儿园-不锈钢-儿童-滑滑梯-床-玩具-淘气堡-厂家-价格 | 挖掘机挖斗和铲斗生产厂家选择徐州崛起机械制造有限公司 | 自清洗过滤器_全自动过滤器_全自动反冲洗过滤器_量子过滤器-滑漮滴 | 工业胀紧套_万向节联轴器_链条-规格齐全-型号选购-非标订做-厂家批发价格-上海乙谛精密机械有限公司 | 宜兴紫砂壶知识分享 - 宜兴壶人 医用空气消毒机-医用管路消毒机-工作服消毒柜-成都三康王 | 安徽泰科检测科技有限公司【官方网站】| 盛源真空泵|空压机-浙江盛源空压机制造有限公司-【盛源官网】 | 除湿机|工业除湿机|抽湿器|大型地下室车间仓库吊顶防爆除湿机|抽湿烘干房|新风除湿机|调温/降温除湿机|恒温恒湿机|加湿机-杭州川田电器有限公司 | 设定时间记录电子秤-自动累计储存电子秤-昆山巨天仪器设备有限公司 | Magnescale探规,Magnescale磁栅尺,Magnescale传感器,Magnescale测厚仪,Mitutoyo光栅尺,笔式位移传感器-苏州连达精密量仪有限公司 | 杭州火蝠电商_京东代运营_拼多多全托管代运营【天猫代运营】 | 涡轮流量计_LWGY智能气体液体电池供电计量表-金湖凯铭仪表有限公司 | 海外整合营销-独立站营销-社交媒体运营_广州甲壳虫跨境网络服务 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 无菌检查集菌仪,微生物限度仪器-苏州长留仪器百科 | 打造全球沸石生态圈 - 国投盛世 锂电混合机-新能源混合机-正极材料混料机-高镍,三元材料混料机-负极,包覆混合机-贝尔专业混合混料搅拌机械系统设备厂家 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 中医治疗皮肤病_潍坊银康医院「山东」重症皮肤病救治平台 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | 钢制拖链生产厂家-全封闭钢制拖链-能源钢铝拖链-工程塑料拖链-河北汉洋机械制造有限公司 | 青岛球场围网,青岛车间隔离网,青岛机器人围栏,青岛水源地围网,青岛围网,青岛隔离栅-青岛晟腾金属制品有限公司 | 卫生纸复卷机|抽纸机|卫生纸加工设备|做卫生纸机器|小型卫生纸加工需要什么设备|卫生纸机器设备多少钱一台|许昌恒源纸品机械有限公司 | 黑龙江「京科脑康」医院-哈尔滨失眠医院_哈尔滨治疗抑郁症医院_哈尔滨精神心理医院 | 顶呱呱交易平台-行业领先的公司资产交易服务平台 | 算命免费_生辰八字_免费在线算命 - 卜算子算命网 | 丙烷/液氧/液氮气化器,丙烷/液氧/液氮汽化器-无锡舍勒能源科技有限公司 | 屏蔽泵厂家,化工屏蔽泵_维修-淄博泵业 |