2012-02-06 4 views
2

응용 프로그램을 실행하고 행을 선택하면 EmployeeInfoPage에 일부 정보가 전달되어 정상적으로 작동합니다. 내가 뒤로 치고 나서 같은 줄을 선택했을 때. tableController.empInfo = employee; 행에서 충돌합니다. 나는이 내가있는 tableview에서 특정 필드를 설정하는 empInfo를 사용하는 EmployeeInfoTableView.h 그런 다음 동일한 행을 두 번 선택하면 UITableView가 중단됩니다.

@interface EmployeeInfoTableView : UITableViewController <UIActionSheetDelegate , MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>{ 

    NSDictionary *empInfo; 
    NSString *currentPhoneNumber; 
    NSString *currentEmail; 

    UIActionSheet *callConfirm; 
} 

파일입니다 EXC_BAD_ACCESS 오류를

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
EmployeeInfoTableView *tableController = [[EmployeeInfoTableView alloc] init]; 

NSDictionary *employee = [[self.orderedSections valueForKey:[[[self.orderedSections allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 

tableController.empInfo = employee;  

[self.navigationController pushViewController:tableController animated:YES];  

[tableController release]; 
} 

를 얻을.

이 내가 내 개체 중 하나를 해제 할 필요가 becuase

- (void)dealloc{ 
    [super dealloc]; 
    [empInfo dealloc]; 
    [currentEmail dealloc]; 
    [currentPhoneNumber dealloc]; 
    [callConfirm dealloc]; 
} 

내 오류가 내 할당 해제의 방법인가?

이것은 내 iPhone에서 들었던 오류입니다.이 책을 읽는 방법을 모르겠습니다.

Exception Type: EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0xb001fb49 
Crashed Thread: 0 

Thread 0 name: Dispatch queue: com.apple.main-thread 
Thread 0 Crashed: 
0 libobjc.A.dylib     0x31798c98 objc_msgSend + 16 
1 libobjc.A.dylib     0x317a24d2 objc_setProperty_non_gc + 62 
2 libobjc.A.dylib     0x3179a040 objc_setProperty + 20 
3 CorporateDirectory    0x0000e5f0 0x1000 + 54768 
4 CorporateDirectory    0x00003ac2 0x1000 + 10946 
5 UIKit       0x32cc3514 -[UITableView           _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 656 
6 UIKit       0x32d270e4 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 124 
7 Foundation      0x338266ce __NSFireDelayedPerform + 362 
8 CoreFoundation     0x345f4a40  __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8 
9 CoreFoundation     0x345f6ec4 __CFRunLoopDoTimer + 844 
10 CoreFoundation     0x345f783e __CFRunLoopRun + 1082 
11 CoreFoundation     0x34587ebc CFRunLoopRunSpecific + 224 
12 CoreFoundation     0x34587dc4 CFRunLoopRunInMode + 52 
13 GraphicsServices    0x322b2418 GSEventRunModal + 108 
14 GraphicsServices    0x322b24c4 GSEventRun + 56 
15 UIKit       0x32c9dd62 -[UIApplication _run] + 398 
16 UIKit       0x32c9b800 UIApplicationMain + 664 
17 CorporateDirectory    0x00002a52 0x1000 + 6738 
18 CorporateDirectory    0x00002a10 0x1000 + 6672 




Thread 1: 
0 libsystem_kernel.dylib   0x339663ec __workq_kernreturn + 8 
1 libsystem_c.dylib    0x3480f6d8 _pthread_wqthread + 592 
2 libsystem_c.dylib    0x3480fbbc start_wqthread + 0 

Thread 2 name: Dispatch queue: com.apple.libdispatch-manager 
Thread 2: 
0 libsystem_kernel.dylib   0x33966fbc kevent + 24 
1 libdispatch.dylib    0x322df032 _dispatch_mgr_invoke + 706 
2 libdispatch.dylib    0x322e003a _dispatch_queue_invoke + 86 
3 libdispatch.dylib    0x322df5ea _dispatch_worker_thread2 + 186 
4 libsystem_c.dylib    0x3480f58a _pthread_wqthread + 258 
5 libsystem_c.dylib    0x3480fbbc start_wqthread + 0 

Thread 3 name: WebThread 
Thread 3: 
0 libsystem_kernel.dylib   0x33963c00 mach_msg_trap + 20 
1 libsystem_kernel.dylib   0x33963758 mach_msg + 44 
2 CoreFoundation     0x345f52b8 __CFRunLoopServiceMachPort + 88 
3 CoreFoundation     0x345f7562 __CFRunLoopRun + 350 
4 CoreFoundation     0x34587ebc CFRunLoopRunSpecific + 224 
5 CoreFoundation     0x34587dc4 CFRunLoopRunInMode + 52 
6 WebCore       0x3666927e _ZL12RunWebThreadPv + 382 
7 libsystem_c.dylib    0x3480e30a _pthread_start + 242 
8 libsystem_c.dylib    0x3480fbb4 thread_start + 0 

Thread 0 crashed with ARM Thread State: 
r0: 0x0016c020 r1: 0x32f63814  r2: 0x000000a8  r3: 0x0016c020 
r4: 0xb001fb41 r5: 0x00000000  r6: 0x001eeca8  r7: 0x2fdfe8c4 
r8: 0x00a1da00 r9: 0x0016c020  r10: 0x00000003  r11: 0x00161a50 
ip: 0x00000000 sp: 0x2fdfe8a4  lr: 0x317a24d9  pc: 0x31798c98 

CPSR : 당신의 didSelectRowAtIndexPath 방법에서이 줄

[tableController release]; 

을 제거하여 0x00000030

+0

당신이'CorporateDirectory' 클래스는 무엇이야? – Rog

답변

0

보십시오. 이전에 릴리스 된 변수에 액세스하려고하면 EXC_BAD_ACCESS 오류가 발생합니다. 동시에 NSDictionary *employee 오브젝트를 tableController과 함께 출시하고 있습니다.

편집 : 발표되지 않도록 사전에 방지하기 위해 당신이 tableController.empInfo = [employee copy];으로 사전의 필요한 내용을 copy 수 있습니다 후 가장이 상황에 맞게 것이다 tableController를 놓습니다.

+0

고마워요. 그래서 나는 왜 그것이 realeasing 그 오류를 일으키는 지에 관해서는 조금 혼란 스럽다. 나는 그것을 재사용 할 수 있도록 공개했으나 다른 행을 클릭하면 다시 호출하기 때문에 릴리스하지 않아도된다는 것을 이해합니다. 그 가정이 맞습니까? – zach

+0

개체를 해제하는 것은 좋은 습관이지만 우리는주의를 기울여야합니다. '[tableController release];'는 메모리가 낭비되지 않도록하기 위해해야 ​​할 일이다. 불행히도, 당신의 경우에, 당신은 실수로 당신이 나중에 사용해야만했던 물건의 기억을 풀어 버렸습니다. 이것의 한가지 방법은'autorelease'를 사용하는 것입니다. 또 다른 방법은 객체의 내용을'employee'에 복사하는 것입니다. – tipycalFlow

+0

감사합니다. – zach

2

didSelectRowAtIndexPath에 잘못된 것이 보이지 않지만 dealloc 메소드가 올바르지 않습니다. 안 함 코드에서 dealloc을 호출합니다. 즉, 완료 한 객체 만 릴리스합니다.

귀하의 dealloc 방법은 다음과 같아야합니다

- (void)dealloc{ 
    [empInfo release]; 
    [currentEmail release]; 
    [currentPhoneNumber release]; 
    [callConfirm release]; 
    [super dealloc]; 
} 
+0

수퍼 dealloc이 목록의 처음이나 끝에 있다면 차이점은 무엇입니까? – zach

+0

어떤 것이 다른지는 확실치 않지만, 모든 속성에 출시 할 수있는 기회가 있는지 확인하기 위해 마지막에 넣는 것이 논리적이지 않습니다.이 개체는 호출 후에 사라집니다. 비슷하게 나는 항상 [super viewDidLoad] 또는 [super loadView]를 처음에 두어 수정하기 전에 뷰가 올바르게 설정되었는지 확인합니다. – jasondinh

+0

@zach ** 나는 그가'** dealloc'라고 불렀다고 생각하지 않습니다! 아무 문제가 없습니다 ... – tipycalFlow

관련 문제