V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
DavidHu
V2EX  ›  iOS

使用 MagicRecord 遇到读不出数据的问题

  •  1
     
  •   DavidHu · Apr 24, 2015 · 3396 views
    This topic created in 4028 days ago, the information mentioned may be changed or developed.

    大概是这样,做了一个登录的功能,登录后的信息用MR存了,然后回到之前的页面会显示登录人的信息,在viewWillAppear里面会先判断是否有数据,有的话就显示名字。这个时候测试也是可以用MR_findall 找到数据的。

    但是后台关掉app后,再次打开却找不到数据了,按理说都是viewWillAppear用同一种方法找数据,为什么就找到?而且后台也显示Core Data里没有数据……

    贴个GitHub地址,如果有大师愿意指点感激不尽Orz
    https://github.com/DavidHu0921/ClassBoxForCityDLUT

    4 replies    2015-04-24 21:25:30 +08:00
    fogisland
        1
    fogisland  
       Apr 24, 2015
    你说的“用MR存了”确定保存到数据库了吗?手头没有代码,大体记得是这个方法名 MR_saveToPersistentStore
    fogisland
        2
    fogisland  
       Apr 24, 2015   ❤️ 1
    看到你代码了:
    [[NSManagedObjectContext MR_defaultContext] MR_saveOnlySelfWithCompletion:^(BOOL success, NSError *error) {
    NSLog(@"SUCCESS: %d, with ERROR: %@", success, error);
    }];

    换成
    [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
    NSLog(@"SUCCESS: %d, with ERROR: %@", success, error);
    }];

    试试
    DavidHu
        3
    DavidHu  
    OP
       Apr 24, 2015
    @fogisland 感谢~不过试了一下,还是没有数据,应该是没有存进去……
    DavidHu
        4
    DavidHu  
    OP
       Apr 24, 2015
    @fogisland 多谢,是之前的判断方法出了问题,没有存进去,太感谢了🙏
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2317 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 15:51 · PVG 23:51 · LAX 08:51 · JFK 11:51
    ♥ Do have faith in what you're doing.