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

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

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

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

    1. <legend id='EJ4Qu'><style id='EJ4Qu'><dir id='EJ4Qu'><q id='EJ4Qu'></q></dir></style></legend>
    2. <tfoot id='EJ4Qu'></tfoot>

        如何以一對多關系清除/重置所有CoreData

        How to clear/reset all CoreData in one-to-many relationship(如何以一對多關系清除/重置所有CoreData)
          <tbody id='tm2Ae'></tbody>
        <tfoot id='tm2Ae'></tfoot>

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

                  <bdo id='tm2Ae'></bdo><ul id='tm2Ae'></ul>
                • <legend id='tm2Ae'><style id='tm2Ae'><dir id='tm2Ae'><q id='tm2Ae'></q></dir></style></legend>
                  <i id='tm2Ae'><tr id='tm2Ae'><dt id='tm2Ae'><q id='tm2Ae'><span id='tm2Ae'><b id='tm2Ae'><form id='tm2Ae'><ins id='tm2Ae'></ins><ul id='tm2Ae'></ul><sub id='tm2Ae'></sub></form><legend id='tm2Ae'></legend><bdo id='tm2Ae'><pre id='tm2Ae'><center id='tm2Ae'></center></pre></bdo></b><th id='tm2Ae'></th></span></q></dt></tr></i><div class="rnvfvvj" id='tm2Ae'><tfoot id='tm2Ae'></tfoot><dl id='tm2Ae'><fieldset id='tm2Ae'></fieldset></dl></div>
                  本文介紹了如何以一對多關系清除/重置所有CoreData的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  我正在使用 coreData,具有一對多的關系,我有一個文件夾實體和一個文件實體.一個文件夾可以有很多文件等等.

                  I am using coreData, with one -to-many realtionship, I have a folder entity and a file entity. A folder can have many files and so on.

                  所以,我有兩個 ViewController,FolderViewController 和 FileViewController,它們分別包含文件夾和文件.現在我有一個 modalView,它可以從文件夾和文件 viewcontroller 訪問.在這個 VC 中,我有一個按鈕來重置所有數據.因此,當我單擊此按鈕時,我希望所有數據都應重置.

                  So, I have two ViewControllers, FolderViewController and FileViewController which contains folders and files respectively.Now I have a modalView , which is accesible from both folder and file viewcontroller. In this VC I have a button to Reset all Data. So when I click this I want all the data should reset.

                  我使用了這段代碼,這個函數寫在 appdelegate.m 中并從我的 VC 中調用.

                  I used this code,this function is written in appdelegate.m and called from my VC.

                  - (void)resetToDefault
                  {
                      NSError * error;
                      // retrieve the store URL
                      NSURL * storeURL = [[__managedObjectContext persistentStoreCoordinator] URLForPersistentStore:[[[__managedObjectContext persistentStoreCoordinator] persistentStores] lastObject]];
                      // lock the current context
                      [__managedObjectContext lock];
                      [__managedObjectContext reset];//to drop pending changes
                      //delete the store from the current managedObjectContext
                      if ([[__managedObjectContext persistentStoreCoordinator] removePersistentStore:[[[__managedObjectContext persistentStoreCoordinator] persistentStores] lastObject] error:&error])
                      {
                          // remove the file containing the data
                          [[NSFileManager defaultManager] removeItemAtURL:storeURL error:&error];
                          //recreate the store like in the  appDelegate method
                          [[__managedObjectContext persistentStoreCoordinator] addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error];//recreates the persistent store
                      }
                      [__managedObjectContext unlock];
                      //that's it !
                  
                      NSLog(@"buttonReset Pressed");
                  }
                  

                  所以在我關閉視圖時單擊 resetButton 后,我收到此錯誤

                  So after clicking on resetButton when I close the View, I get this error

                  *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator'
                  

                  那么如何解決這個問題.

                  So how to solve this.

                  問候蘭吉特

                  推薦答案

                  這個問題我已經解決了,下面是代碼,

                  I have solved this problem, below is the code,

                  這個函數已經寫在appdelegate.m中

                  This function has been written in appdelegate.m

                  - (void) resetApplicationModel
                  {
                      NSError *error;
                      NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"AppName.sqlite"];
                      [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil];
                      for (NSManagedObject *ct in [self.managedObjectContext registeredObjects]) {
                          [self.managedObjectContext deleteObject:ct];
                      }
                  
                      //Make new persistent store for future saves   
                      if (![self.persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
                          // do something with the error
                      }  
                  }
                  

                  在我的 SettingsViewController 中,我在以這種方式單擊的重置按鈕上調用它.

                  And in my SettingsViewController, I am calling this on resetbutton clicked in this way.

                  - (void)resetButtonclicked
                  {
                  AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
                          [appDelegate resetApplicationModel];  
                  }  
                  

                  問候蘭吉特.

                  這篇關于如何以一對多關系清除/重置所有CoreData的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  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(圖標已經包含光澤效果)
                  How does UIEdgeInsetsMake work?(UIEdgeInsetsMake 是如何工作的?)
                  UIProgressView and Custom Track and Progress Images (iOS 5 properties)(UIProgressView 和自定義跟蹤和進度圖像(iOS 5 屬性))

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

                      <tbody id='VJyjZ'></tbody>
                      1. <tfoot id='VJyjZ'></tfoot>
                        <legend id='VJyjZ'><style id='VJyjZ'><dir id='VJyjZ'><q id='VJyjZ'></q></dir></style></legend>
                        <i id='VJyjZ'><tr id='VJyjZ'><dt id='VJyjZ'><q id='VJyjZ'><span id='VJyjZ'><b id='VJyjZ'><form id='VJyjZ'><ins id='VJyjZ'></ins><ul id='VJyjZ'></ul><sub id='VJyjZ'></sub></form><legend id='VJyjZ'></legend><bdo id='VJyjZ'><pre id='VJyjZ'><center id='VJyjZ'></center></pre></bdo></b><th id='VJyjZ'></th></span></q></dt></tr></i><div class="xpnzrbd" id='VJyjZ'><tfoot id='VJyjZ'></tfoot><dl id='VJyjZ'><fieldset id='VJyjZ'></fieldset></dl></div>
                          <bdo id='VJyjZ'></bdo><ul id='VJyjZ'></ul>

                            主站蜘蛛池模板: 高低温万能试验机-复合材料万能试验机-馥勒仪器 | 便携式表面粗糙度仪-彩屏硬度计-分体式粗糙度仪-北京凯达科仪科技有限公司 | 液氨泵,液化气泵-淄博「亚泰」燃气设备制造有限公司 | SEO网站优化,关键词排名优化,苏州网站推广-江苏森歌网络 | 学生作文网_中小学生作文大全与写作指导 | 宝鸡市人民医院 | 一氧化氮泄露报警器,二甲苯浓度超标报警器-郑州汇瑞埔电子技术有限公司 | 金属抛光机-磁悬浮抛光机-磁力研磨机-磁力清洗机 - 苏州冠古科技 | 许昌奥仕达自动化设备有限公司| 哈尔滨京科脑康神经内科医院-哈尔滨治疗头痛医院-哈尔滨治疗癫痫康复医院 | 天津仓储物流-天津电商云仓-天津云仓一件代发-博程云仓官网 | 蒸汽热收缩机_蒸汽发生器_塑封机_包膜机_封切收缩机_热收缩包装机_真空机_全自动打包机_捆扎机_封箱机-东莞市中堡智能科技有限公司 | 517瓜水果特产网|一个专注特产好物的网站| 开平机_纵剪机厂家_开平机生产厂家|诚信互赢-泰安瑞烨精工机械制造有限公司 | 庭院灯_太阳能景观灯_草坪灯厂家_仿古壁灯-重庆恒投科技 | 重庆波纹管|重庆钢带管|重庆塑钢管|重庆联进管道有限公司 | 无缝方管|无缝矩形管|无缝方矩管|无锡方管厂家 | 国际船舶网 - 船厂、船舶、造船、船舶设备、航运及海洋工程等相关行业综合信息平台 | 橡胶电子拉力机-塑料-微电脑电子拉力试验机厂家-江苏天源 | 防水试验机_防水测试设备_防水试验装置_淋雨试验箱-广州岳信试验设备有限公司 | 井式炉-台车式回火炉-丹阳市电炉厂有限公司| 小型UV打印机-UV平板打印机-大型uv打印机-UV打印机源头厂家 |松普集团 | 气体热式流量计-定量控制流量计(空气流量计厂家)-湖北南控仪表科技有限公司 | 福州时代广告制作装饰有限公司-福州广告公司广告牌制作,福州展厅文化墙广告设计, | 高铝轻质保温砖_刚玉莫来石砖厂家_轻质耐火砖价格 | 高低温试验箱-模拟高低温试验箱订制-北京普桑达仪器科技有限公司【官网】 | 直齿驱动-新型回转驱动和回转支承解决方案提供商-不二传动 | 尚为传动-专业高精密蜗轮蜗杆,双导程蜗轮蜗杆,蜗轮蜗杆减速机,蜗杆减速机生产厂家 | 工业PH计|工业ph酸度计|在线PH计价格-合肥卓尔仪器仪表有限公司 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 维泰克Veertek-锂电池微短路检测_锂电池腐蚀检测_锂电池漏液检测 | 附着力促进剂-尼龙处理剂-PP处理剂-金属附着力处理剂-东莞市炅盛塑胶科技有限公司 | 武汉天安盾电子设备有限公司 - 安盾安检,武汉安检门,武汉安检机,武汉金属探测器,武汉测温安检门,武汉X光行李安检机,武汉防爆罐,武汉车底安全检查,武汉液体探测仪,武汉安检防爆设备 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 紫外线老化试验箱_uv紫外线老化试验箱价格|型号|厂家-正航仪器设备 | 包头市鑫枫装饰有限公司| 科昊仪器超纯水机系统-可成气相液氮罐-美菱超低温冰箱-西安昊兴生物科技有限公司 | 工装定制/做厂家/公司_工装订做/制价格/费用-北京圣达信工装 | 山东锐智科电检测仪器有限公司_超声波测厚仪,涂层测厚仪,里氏硬度计,电火花检漏仪,地下管线探测仪 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 土壤有机碳消解器-石油|表层油类分析采水器-青岛溯源环保设备有限公司 | 贵阳用友软件,贵州财务软件,贵阳ERP软件_贵州优智信息技术有限公司 |