내 문제 : 모든 기능이 제대로 작동하지만 TahDoodle (큰 괴상한 목장에서 배울 수있는 프로그램) (Objective-C 프로그래밍 : The Big Nerd Ranch Guide) ., 프로그램 충돌 본인은 "누출"악기에보고했다 많은 누수를 보았다하지만 난 그것을 해결하는 방법을 몰라 여기 파일을 열면 TahDoodle이 작동을 멈 춥니 다.
내 코드입니다 :..BNRDocument.m
#import "BNRDocument.h"
@implementation BNRDocument
# pragma mark - NSDocument Overrides
- (id)init
{
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, return nil.
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return @"BNRDocument";
}
# pragma mark - Actions
- (IBAction)createNewItem:(id)sender
{
// Falls es noch kein Array gibt, erstellen Sie einfach
// eines, in dem unsere neue Aufgabe gespeichert wird
if (!toDoItems) {
toDoItems = [[NSMutableArray alloc]init];
}
[toDoItems addObject:@"New Item"];
// -reloadDate aktualisiert die Tabellenansicht und fordert von
// dataSource (das in diesem Fall zufällig dieses BNRDocument ist)
// neue Daten zur Darstellung an
[itemTableView reloadData];
// -updateChangeCount: teilt der Anwendung mit, ob im Dokument
// ungespeicherte Änderungen vorhanden sind oder nicht.
// NSChangeDone kennzeichnet das Dokument als ungespeichert
[self updateChangeCount:NSChangeDone];
}
# pragma mark - Data Source Methods
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tv
{
// Diese Tabellenansicht soll die todoItems darstellen,
// und somit ist die Zahl der Einträge in der Tabellenansicht
// gleich der Zahl der Objekte im Array
return [toDoItems count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
// Gibt das Element aus todoItems zurück, das mit der Zelle
// korrespodiert, die die Tabellenansicht darstellen will
return [toDoItems objectAtIndex:row];
}
- (void)tableView:(NSTableView *)tableView
setObjectValue:(id)object
forTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row
{
// Ändert der Benutzer ein To-do-Element in der Tabellenansicht
// wird das totoItems-Array aktualisiert
[toDoItems replaceObjectAtIndex:row withObject:object];
// Dann wird das Dokument gekennzeichnet, es habe
// ungespeicherte Änderungen
[self updateChangeCount:NSChangeDone];
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
// Diese Methode wird beim Speichern unseres Dokuments aufgerufen
// Wir sollen dafür sorgen, dass der Aufrufer ein NSData-Objekt bekommt,
// das unsere Daten umhüllt um sie auf Festplatte schreiben zu können
// Falls es kein Array gibt, schreibn wir fürs Erste ein leeres Array
if (!toDoItems) {
toDoItems = [[NSMutableArray alloc]init];
}
// Packt unser toDoItems-Array in ein NS Data-Objekt
NSData *data = [NSPropertyListSerialization dataWithPropertyList:toDoItems
format:NSPropertyListXMLFormat_v1_0
options:0
error:outError];
// Gibt das neu gepackte NSData-Objekt zurück
return data;
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
// Diese Methode wird aufgerufen, wenn ein Dokument geladen wird
// Wir bekommen ein NSData-Objekt und sollen daraus unsere Daten ziehen
// Extrahiert ToDoItems
toDoItems = [NSPropertyListSerialization propertyListWithData:data
options:NSPropertyListMutableContainers
format:NULL
error:outError];
// Gibt unabhängig vom obigen Aufruf Erfolg oder Misslingen zurück
return (toDoItems !=nil);
}
@end
BNRDocument.h
#import <Cocoa/Cocoa.h>
@interface BNRDocument : NSDocument <NSTableViewDataSource>
{
NSMutableArray *toDoItems;
IBOutlet NSTableView *itemTableView;
}
-(IBAction)createNewItem:(id)sender;
@end
나는 5 회 alle 그 코드 부분을 빨간색과 내 여자 친구는 2 번했다. 그러나이 책에 쓰여있는 모든 내용은이 게시물의 수정 사항을 적용한 것입니다. http://forums.bignerdranch.com/viewtopic.php?f=160&t=3494
나를 도울 수 있다면 좋을 것입니다. 주셔서 감사합니다 :)
행복을 빌며, 기독교
편집 : 가 좋아, 난 그냥 콘솔 잊었 :
[Switching to process 746 thread 0x0]
[Switching to process 746 thread 0x3d03]
[Switching to process 746 thread 0x903]
2014-04-27 22:03:55.137 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
2014-04-27 22:03:55.146 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
2014-04-27 22:04:02.338 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
2014-04-27 22:04:02.342 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
2014-04-27 22:04:06.169 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
2014-04-27 22:04:06.175 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
2014-04-27 22:04:09.528 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
2014-04-27 22:04:09.532 TahDoodle[746:903] *** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)
kill
quit
을하지만 그게 무슨 뜻인지 모르겠어요. 하지만 그것은 읽기 오류가 아닌 것 같습니다.
EDIT2 :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>New Item</string>
<string>New Item</string>
</array>
</plist>
EDIT3
하나 밖에없는 브레이크 포인트는 여기에 있습니다 : :
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
// Gibt das Element aus todoItems zurück, das mit der Zelle
// korrespodiert, die die Tabellenansicht darstellen will
return [toDoItems objectAtIndex:row];
도구 방법은 다음로드해야 파일의 내용입니다 예외 이유를 찾는 것은 매우 좋습니다. 고마워. 모든 "반환"에서 수동 중단 점을 설정했습니다.
것은 ... 항목이로드됩니다. 프로그램에서 볼 수는 있지만 창을 클릭하면 프로그램이 충돌합니다 : EXC_BAD_ACCESS. 내가 저장 한 파일을 더블 클릭하면
는 TahDoodle가 열리고 다음이 메시지와 함께 즉시 충돌 :
[...]
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x000000000000001b
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: objectAtIndex:
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x00007fff89b1108c objc_msgSend_vtable10 + 12
1 com.apple.AppKit 0x00007fff8275aa7c -[NSTableView preparedCellAtColumn:row:] + 323
2 com.apple.AppKit 0x00007fff82773963 -[NSTableView _drawContentsAtRow:column:withCellFrame:] + 47
3 com.apple.AppKit 0x00007fff827729fc -[NSTableView drawRow:clipRect:] + 1242
4 com.apple.AppKit 0x00007fff827722ef -[NSTableView drawRowIndexes:clipRect:] + 369
5 com.apple.AppKit 0x00007fff82770c9c -[NSTableView drawRect:] + 1302
6 com.apple.AppKit 0x00007fff82766cc5 -[NSView _drawRect:clip:] + 3390
7 com.apple.AppKit 0x00007fff82765938 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 1325
8 com.apple.AppKit 0x00007fff82765ca2 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2199
9 com.apple.AppKit 0x00007fff82765ca2 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2199
10 com.apple.AppKit 0x00007fff82765ca2 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2199
11 com.apple.AppKit 0x00007fff82765ca2 -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] + 2199
12 com.apple.AppKit 0x00007fff8276400a -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 767
13 com.apple.AppKit 0x00007fff82763b2c -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] + 254
14 com.apple.AppKit 0x00007fff827603de -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] + 2683
15 com.apple.AppKit 0x00007fff826d9c0e -[NSView displayIfNeeded] + 969
16 com.apple.AppKit 0x00007fff826d4aba _handleWindowNeedsDisplay + 678
17 com.apple.Foundation 0x00007fff82449bc5 __NSFireTimer + 114
18 com.apple.CoreFoundation 0x00007fff832b8bb8 __CFRunLoopRun + 6488
19 com.apple.CoreFoundation 0x00007fff832b6d8f CFRunLoopRunSpecific + 575
20 com.apple.HIToolbox 0x00007fff87ac37ee RunCurrentEventLoopInMode + 333
21 com.apple.HIToolbox 0x00007fff87ac35f3 ReceiveNextEventCommon + 310
22 com.apple.HIToolbox 0x00007fff87ac34ac BlockUntilNextEventMatchingListInMode + 59
23 com.apple.AppKit 0x00007fff826a9eb2 _DPSNextEvent + 708
24 com.apple.AppKit 0x00007fff826a9801 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 155
25 com.apple.AppKit 0x00007fff8266f68f -[NSApplication run] + 395
26 com.apple.AppKit 0x00007fff826683b0 NSApplicationMain + 364
27 BuRo.TahDoodle 0x00000001000015e4 start + 52
Thread 1: Dispatch queue: com.apple.libdispatch-manager
0 libSystem.B.dylib 0x00007fff89bdbc0a kevent + 10
1 libSystem.B.dylib 0x00007fff89bddadd _dispatch_mgr_invoke + 154
2 libSystem.B.dylib 0x00007fff89bdd7b4 _dispatch_queue_invoke + 185
3 libSystem.B.dylib 0x00007fff89bdd2de _dispatch_worker_thread2 + 252
4 libSystem.B.dylib 0x00007fff89bdcc08 _pthread_wqthread + 353
5 libSystem.B.dylib 0x00007fff89bdcaa5 start_wqthread + 13
Thread 2:
0 libSystem.B.dylib 0x00007fff89bdca2a __workq_kernreturn + 10
1 libSystem.B.dylib 0x00007fff89bdce3c _pthread_wqthread + 917
2 libSystem.B.dylib 0x00007fff89bdcaa5 start_wqthread + 13
Thread 3:
0 libSystem.B.dylib 0x00007fff89bdca2a __workq_kernreturn + 10
1 libSystem.B.dylib 0x00007fff89bdce3c _pthread_wqthread + 917
2 libSystem.B.dylib 0x00007fff89bdcaa5 start_wqthread + 13
[...]
누출 기기를 잊어 버리면 하드 드라이브 공간이 부족한 경우가 아니라면 누출 된 객체가 충돌을 일으키지 않습니다. 충돌시 콘솔에 출력되는 내용은 무엇입니까? –
내 편집 내용을 보려면 "편집"및 "편집 2"를 참조하십시오. 당신의 도움을 주셔서 감사합니다. –
그 오류는 항목이없는 배열이 있고 어딘가에서 배열의 첫 번째 항목 (존재하지 않음)에 액세스하려는 일부 코드가 있음을 의미합니다. 내가 게시 한 코드 어디에도 버그가 표시되지 않습니다. 아마도 "모든 예외"에 중단 점을 설정하여 먼저 실패한 코드 줄을 찾은 다음 스택 추적이 무엇인지 알려주십시오. 다음은 "모든"예외에 중단 점을 두는 방법입니다. https://developer.apple.co.kr/library/ios/recipes/xcode_help-breakpoint_navigator/articles/adding_an_exception_breakpoint.html –