菜鸟教程小白 发表于 2022-12-12 16:06:17

ios - NSFetchedResultsController 全部删除


                                            <p><p>AcaniChat 与原生 iPhone 消息应用程序一样,具有清除所有消息的方法:</p>

<pre><code>for (Message *message in ) {
    ;
}
if (!) {
    // TODO: Handle the error appropriately.
    NSLog(@&#34;Delete message error %@, %@&#34;, error, );
}
</code></pre>

<p>但是,只有当有大量消息被删除(足以使某些消息不在屏幕上)时,AcaniChat 才会崩溃并出现错误:</p>

<pre><code>2011-04-10 01:06:17.629 AcaniChat Serious application error.Exception was caught during Core Data change processing.This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification.CoreData could not fulfill a fault for &#39;0x4d7d050 &lt;x-coredata://F07CAEF9-5F38-4A1F-BA17-52A3E2E56978/Message/p42&gt;&#39; with userInfo {
    NSAffectedObjectsErrorKey =   (
      &#34;&lt;Message: 0x4d665b0&gt; (entity: Message; id: 0x4d7d050 &lt;x-coredata://F07CAEF9-5F38-4A1F-BA17-52A3E2E56978/Message/p42&gt; ; data: &lt;fault&gt;)&#34;
    );
}
2011-04-10 01:06:17.721 AcaniChat Delete message error Error Domain=NSCocoaErrorDomain Code=133000 &#34;The operation couldn’t be completed. (Cocoa error 133000.)&#34; UserInfo=0x4d9cf70 {NSAffectedObjectsErrorKey=(
    &#34;&lt;Message: 0x4d665b0&gt; (entity: Message; id: 0x4d7d050 &lt;x-coredata://F07CAEF9-5F38-4A1F-BA17-52A3E2E56978/Message/p42&gt; ; data: &lt;fault&gt;)&#34;
), NSUnderlyingException=CoreData could not fulfill a fault for &#39;0x4d7d050 &lt;x-coredata://F07CAEF9-5F38-4A1F-BA17-52A3E2E56978/Message/p42&gt;&#39;}, {
    NSAffectedObjectsErrorKey =   (
      &#34;&lt;Message: 0x4d665b0&gt; (entity: Message; id: 0x4d7d050 &lt;x-coredata://F07CAEF9-5F38-4A1F-BA17-52A3E2E56978/Message/p42&gt; ; data: &lt;fault&gt;)&#34;
    );
    NSUnderlyingException = &#34;CoreData could not fulfill a fault for &#39;0x4d7d050 &lt;x-coredata://F07CAEF9-5F38-4A1F-BA17-52A3E2E56978/Message/p42&gt;&#39;&#34;;
}
2011-04-10 01:06:18.036 AcaniChat CoreAnimation: ignoring exception: CoreData could not fulfill a fault for &#39;0x4d7d050 &lt;x-coredata://F07CAEF9-5F38-4A1F-BA17-52A3E2E56978/Message/p42&gt;&#39;
</code></pre>

<p>我该如何解决这个问题?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我通过设置 <code>fetchedResultsController_.delegate = nil</code> 解决了这个问题,删除了 <code>cellMap</code> 中的所有对象(这实际上是 <code>UITableView *chatContent</code> 因为我将 <code>NSDate</code> 对象添加到 <code>cellMap</code> 用于时间戳单元格),然后设置 <code>fetchedResultsController_.delegate = self</code> 并执行再次获取请求。</p>

<pre><code>NSError *error;
fetchedResultsController.delegate = nil;               // turn off delegate callbacks
for (Message *message in ) {
    ;
}
if (!) {
    // TODO: Handle the error appropriately.
    NSLog(@&#34;Delete message error %@, %@&#34;, error, );
}
fetchedResultsController.delegate = self;            // reconnect after mass delete
if (!) { // resync controller
    // TODO: Handle the error appropriately.
    NSLog(@&#34;fetchMessages error %@, %@&#34;, error, );
}
;
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - NSFetchedResultsController 全部删除,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/5609921/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/5609921/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - NSFetchedResultsController 全部删除