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>
                            主站蜘蛛池模板: 板材品牌-中国胶合板行业十大品牌-环保板材-上海声达板材 | 超声波分散机-均质机-萃取仪-超声波涂料分散设备-杭州精浩 | 防渗膜厂家|养殖防渗膜|水产养殖防渗膜-泰安佳路通工程材料有限公司 | 泰兴市热钻机械有限公司-热熔钻孔机-数控热熔钻-热熔钻孔攻牙一体机 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | 橡胶接头|可曲挠橡胶接头|橡胶软接头安装使用教程-上海松夏官方网站 | 深圳善跑体育产业集团有限公司_塑胶跑道_人造草坪_运动木地板 | 间甲酚,间甲酚厂家-山东祥东新材料 | 智能型高压核相仪-自动开口闪点测试仪-QJ41A电雷管测试仪|上海妙定 | 上海物流公司,上海货运公司,上海物流专线-优骐物流公司 | 餐饮加盟网_特色餐饮连锁加盟店-餐饮加盟官网 | 组织研磨机-高通量组织研磨仪-实验室多样品组织研磨机-东方天净 传递窗_超净|洁净工作台_高效过滤器-传递窗厂家广州梓净公司 | 光栅尺_Magnescale探规_磁栅尺_笔式位移传感器_苏州德美达 | 淄博不锈钢,淄博不锈钢管,淄博不锈钢板-山东振远合金科技有限公司 | 蜗轮丝杆升降机-螺旋升降机-丝杠升降机厂家-润驰传动 | 乐考网-银行从业_基金从业资格考试_初级/中级会计报名时间_中级经济师 | 标准件-非标紧固件-不锈钢螺栓-非标不锈钢螺丝-非标螺母厂家-三角牙锁紧自攻-南京宝宇标准件有限公司 | 手机存放柜,超市储物柜,电子储物柜,自动寄存柜,行李寄存柜,自动存包柜,条码存包柜-上海天琪实业有限公司 | 建大仁科-温湿度变送器|温湿度传感器|温湿度记录仪_厂家_价格-山东仁科 | 淋巴细胞分离液_口腔医疗器材-精欣华医疗器械(无锡)有限公司 | 上海小程序开发-小程序制作-上海小程序定制开发公司-微信商城小程序-上海咏熠 | 恒温油槽-恒温水槽-低温恒温槽厂家-宁波科麦仪器有限公司 | 发电机组|柴油发电机组-批发,上柴,玉柴,潍柴,康明斯柴油发电机厂家直销 | 档案密集柜_手动密集柜_智能密集柜_内蒙古档案密集柜-盛隆柜业内蒙古密集柜直销中心 | 【孔氏陶粒】建筑回填陶粒-南京/合肥/武汉/郑州/重庆/成都/杭州陶粒厂家 | 有源电力滤波装置-电力有源滤波器-低压穿排电流互感器|安科瑞 | 硫化罐-电加热蒸汽硫化罐生产厂家-山东鑫泰鑫智能装备有限公司 | 流程管理|流程管理软件|企业流程管理|微宏科技-AlphaFlow_流程管理系统软件服务商 | 炒货机-炒菜机-炒酱机-炒米机@霍氏机械 | 蔬菜配送公司|蔬菜配送中心|食材配送|饭堂配送|食堂配送-首宏公司 | 缠绕机|缠绕膜包装机|缠绕包装机-上海晏陵智能设备有限公司 | 塑料熔指仪-塑料熔融指数仪-熔体流动速率试验机-广东宏拓仪器科技有限公司 | LED灯杆屏_LED广告机_户外LED广告机_智慧灯杆_智慧路灯-太龙智显科技(深圳)有限公司 | 壹车网 | 第一时间提供新车_资讯_报价_图片_排行! | 防水套管厂家-柔性防水套管-不锈钢|刚性防水套管-天翔管道 | 湖南教师资格网-湖南教师资格证考试网 | 钢格板_钢格栅_格栅板_钢格栅板 - 安平县鑫拓钢格栅板厂家 | 天津试验仪器-电液伺服万能材料试验机,恒温恒湿标准养护箱,水泥恒应力压力试验机-天津鑫高伟业科技有限公司 | 微学堂-电动能源汽车评测_电动车性能分享网 | 行星齿轮减速机,减速机厂家,山东减速机-淄博兴江机械制造 | 广东风淋室_广东风淋室厂家_广东风淋室价格_广州开源_传递窗_FFU-广州开源净化科技有限公司 |