2011-02-03 6 views
1

작은 텍스트 편집기를 개발 중이며 테이블보기 템플릿을 사용하여 앱 문서 디렉토리의 내용을 나열하는 코드가 추가되었습니다. 모두 괜찮습니다. 디렉토리와 테이블보기는 그들을 보여 주지만 내가 스크롤을 시작하면, 그것은 충돌합니다. 나는 무언가가 출시 될 때 필요 없다고 생각합니다. 여기에 당신이 문자열에 objectAtIndex: 전화를 시도하는 스택 트레이스에 따르면 코드와 충돌 로그 :스크롤 할 때 UITableView에서 크래시가 발생합니다.

RootViewController.m

NSFileManager *directoryContent; 
- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 
    [self listDumpFiles]; 
} 
// Customize the number of sections in the table view. 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [directoryContent count]; 
} 


// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell. 
    cell.text = [directoryContent objectAtIndex:indexPath.row]; 
    return cell; 
} 
- (void)listDumpFiles { 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: documentsDirectory]; 

    NSLog(@"%@", documentsDirectory); 
    return; 
} 

충돌 로그

2011-02-03 17:38:16.516 uNotes[15352:40b] /Users/pablo/Library/Application Support/iPhone Simulator/4.2/Applications/DF298F31-5723-4A1E-9EAA-3353C34BDCB2/Documents 
2011-02-03 17:38:17.412 uNotes[15352:40b] -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x9b243f0 
2011-02-03 17:38:17.413 uNotes[15352:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x9b243f0' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00da7be9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00efc5c2 objc_exception_throw + 47 
    2 CoreFoundation      0x00da96fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00d19366 ___forwarding___ + 966 
    4 CoreFoundation      0x00d18f22 _CF_forwarding_prep_0 + 50 
    5 uNotes        0x0000238c -[RootViewController tableView:cellForRowAtIndexPath:] + 216 
    6 UIKit        0x003247fa -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634 
    7 UIKit        0x0031a77f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75 
    8 UIKit        0x0032f450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561 
    9 UIKit        0x00327538 -[UITableView layoutSubviews] + 242 
    10 QuartzCore       0x01c65451 -[CALayer layoutSublayers] + 181 
    11 QuartzCore       0x01c6517c CALayerLayoutIfNeeded + 220 
    12 QuartzCore       0x01c5e37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 
    13 QuartzCore       0x01c5e0d0 _ZN2CA11Transaction6commitEv + 292 
    14 QuartzCore       0x01c8e7d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99 
    15 CoreFoundation      0x00d88fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 
    16 CoreFoundation      0x00d1e0e7 __CFRunLoopDoObservers + 295 
    17 CoreFoundation      0x00ce6bd7 __CFRunLoopRun + 1575 
    18 CoreFoundation      0x00ce6240 CFRunLoopRunSpecific + 208 
    19 CoreFoundation      0x00ce6161 CFRunLoopRunInMode + 97 
    20 GraphicsServices     0x016dc268 GSEventRunModal + 217 
    21 GraphicsServices     0x016dc32d GSEventRun + 115 
    22 UIKit        0x002bf42e UIApplicationMain + 1160 
    23 uNotes        0x00001fc0 main + 102 
    24 uNotes        0x00001f51 start + 53 
) 
terminate called after throwing an instance of 'NSException' 
Program received signal: “SIGABRT”. 
(gdb) 

답변

4

을 떠났다. 아마도 메모리 관리 문제 일 것입니다. Enable zombies을 사용하면 호출중인 개체에 대한 자세한 정보를 얻을 수 있습니다.

UPDATE는

내가 directoryContentsAtPath:는 오토 릴리즈 객체를 반환 생각 아마도이 줄

directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: documentsDirectory];

입니다. directoryContent이 헤더에 @property(nonatomic, retain)으로 설정되어있는 경우 self.directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath: documentsDirectory];을 사용하여 설정할 수 있으며 NSFileManager에 의해 반환 된 객체가 자동으로 유지됩니다. 그렇지 않으면 directoryContent = [[[NSFileManager defaultManager] directoryContentsAtPath: documentsDirectory] retain];으로 전화 할 수 있지만 더 이상 필요없는 객체는 해제해야합니다.

+0

나는 이것을 얻었고, 무엇인가 놓치고 필요하다고 생각한다. '2011-02-03 17 : 54 : 51.102 uNotes [15418 : 40b]/Users/pablo/Library/Application Support/iPhone Simulator/4.2/응용 프로그램/DF298F31-5723-4A1E-9EAA-3353C34BDCB2/Documents 2011-02-03 17:54:56.785 uNotes [15418 : 40b] *** - [NSArrayM objectAtIndex :] : 메시지가 할당 취소 된 인스턴스에 전송 됨 0x921fc60 (gdb) ' – pmerino

+0

@ zak0xsis 내 업데이트를 확인하십시오 –

+0

와우! 그것은 형제 일했다! 너무 고마워! :) 여기에 투표하는 방법은 무엇입니까? – pmerino

관련 문제