PDFDocument removePageAtIndex:不更新時工作到Mac OS X 10.11
我使用PDFKit框架到我的可可應用程序的PDFViewer.When我想刪除的頁面的一個從PDFDocument的應用凍結在代碼
[[self pdfDocument] removePageAtIndex:0]; // can see this Problem only in Mac OS X 10.11
行這完美的作品,當我在的Mac OS上運行的應用程序X 10.10
我讀了所有相關文件蘋果,但我還沒有得到任何解決方案。
這裏是回溯:
* thread #1: tid = 0x85e1, 0x00007fff92571f5e libsystem_kernel.dylib`__psynch_cvwait + 10, queue = 'com.apple.main-thread', stop reason = signal SIGTERM
frame #0: 0x00007fff92571f5e libsystem_kernel.dylib`__psynch_cvwait + 10
frame #1: 0x00000001006c05f7 libsystem_pthread.dylib`_pthread_cond_wait + 767
frame #2: 0x00007fff904c6e32 Foundation`-[__NSOperationInternal _waitUntilFinished:] + 131
frame #3: 0x00007fff904921fa Foundation`-[NSOperationQueue waitUntilAllOperationsAreFinished] + 254
* frame #4: 0x000000010017efe1 Neat`-[NRMPDFCoordinator waitUntilAllOperationsAreFinished](self=0x0000608000ad3be0, _cmd=0x00007fff8877e285) + 145 at NRMPDFCoordinator.m:1362
frame #5: 0x00000001000109cf Neat`-[NRMItemEditorDocument saveDocumentWithDelegate:didSaveSelector:contextInfo:](self=0x000060000094a190, _cmd=0x00007fff88777581, delegate=0x0000000000000000, didSaveSelector=0x0000000000000000, contextInfo=0x0000000000000000) + 1151 at NRMItemEditorDocument.m:325
frame #6: 0x000000010001018a Neat`-[NRMItemEditorDocument saveDocument:](self=0x000060000094a190, _cmd=0x00007fff8874cbb4, sender=0x00006080003a8b20) + 58 at NRMItemEditorDocument.m:234
frame #7: 0x0000000100013bef Neat`-[NRMItemEditorWindowController saveAndClose:](self=0x00006080003a8b20, _cmd=0x00000001002cf2d2, sender=0x000060000094a5b0) + 95 at NRMItemEditorWindowController.m:244
frame #8: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #9: 0x00007fff87fc79b5 AppKit`-[NSApplication sendAction:to:from:] + 460
frame #10: 0x00007fff87fd9bb2 AppKit`-[NSControl sendAction:to:] + 86
frame #11: 0x00007fff87fd9adc AppKit`__26-[NSCell _sendActionFrom:]_block_invoke + 131
frame #12: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #13: 0x00007fff87fd9a39 AppKit`-[NSCell _sendActionFrom:] + 144
frame #14: 0x00007fff87068082 libsystem_trace.dylib`_os_activity_initiate + 75
frame #15: 0x00007fff87fd805e AppKit`-[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
frame #16: 0x00007fff88020d1c AppKit`-[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
frame #17: 0x00007fff87fd6788 AppKit`-[NSControl mouseDown:] + 669
frame #18: 0x00007fff88524575 AppKit`-[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
frame #19: 0x00007fff88525559 AppKit`-[NSWindow _reallySendEvent:isDelayedEvent:] + 212
frame #20: 0x00007fff87f6ad31 AppKit`-[NSWindow sendEvent:] + 517
frame #21: 0x00007fff87eeaccb AppKit`-[NSApplication sendEvent:] + 2540
frame #22: 0x0000000100225f35 Neat`-[NRMApplication sendEvent:](self=0x00006000001205a0, _cmd=0x00007fff88749e04, event=0x0000608000725640) + 1141 at NRMApplication.m:95
frame #23: 0x00007fff87d51f3e AppKit`-[NSApplication run] + 796
frame #24: 0x00007fff87d1b162 AppKit`NSApplicationMain + 1176
frame #25: 0x0000000100012d67 Neat`main(argc=3, argv=0x00007fff5fbff718) + 119 at main.m:21
frame #26: 0x0000000100001e74 Neat`start + 52
這裏是我使用PDFDocument的removePageAtIndex方法
-(NSError *)removePageOpImpl:(NRMPDFOperation *)op
{
NSLog(@"\n Inside removePageOpImpl Method ...");
NSError* error = [self loadDocument];
if(!error)
{
NSUInteger index = [self pageIndexForId:[op pageId]];
NSLog(@"Page count: %ld", [self pageCount]);
if(index < [self pageCount])
{
NSLog(@"PDF Document:-- %@", [self pdfDocument]);
NSLog(@"Index is: %ld", index);
@try {
[(PDFDocument *)[self pdfDocument] removePageAtIndex:index];//At this line the app getting freezed and control is ended.
NSLog(@"Page count after delete: %ld", [self pageCount]);
}
@catch (NSException *exception) {
NSLog(@"Exception: %@", exception);
}
@finally {
NSLog(@"Finally called");
[[self mutablePageIdList] removeObjectAtIndex:index];
[self updatePageLabelsFromIndex:index];
[self updateChangeCount:NSChangeDone];
self.contentsChanged = YES;
}
}
else
{
// TODO: error
}
}
return error;
}
任何人都可以請建議我可能是什麼問題的方法......還附上阻塞UI的隊列屏幕截圖
我嘗試在主隊列上應用dispatch_async到PDFDocument頁面刪除操作,如下所示
- (NSError *)removePageOpImpl:(NRMPDFOperation *)op
{
NSError* error = [self loadDocument];
if(!error)
{
NSUInteger index = [self pageIndexForId:[op pageId]];
if(index < [self pageCount])
{
dispatch_async(dispatch_get_main_queue(), ^{
[[self pdfDocument] removePageAtIndex:index];
[[self mutablePageIdList] removeObjectAtIndex:index];
[self updatePageLabelsFromIndex:index];
[self updateChangeCount:NSChangeDone];
self.contentsChanged = YES;
});
}
else
{
// TODO: error
}
}
return error;
}
現在的應用程序沒有掛,但我陷入了另一個問題。我有其他的操作應該在removePageOpImpl操作後同步運行。但是它們在removePageOpImpl完成之前執行,它正在改變我的應用程序的行爲。你能建議我如何在removePageOpImpl後同步執行其他操作。我讀了關於完成處理程序,但在這種情況下,我很困惑如何使用它。
請建議
你可以發佈堆棧回溯? – Aderstedt
@Aderstedt:我試圖打印回溯但沒有打印。 –
您是否正在Xcode內運行應用程序?如果是這樣,你應該在那裏看到回溯。 – Aderstedt