当同一行被选择两次时 UITableView 崩溃
当我运行应用程序并选择一行时,它会将一些信息传递给 EmployeeInfoPage 并且工作正常。当我回击然后选择同一行时。它在 tableController.empInfo = employee; 行崩溃。我收到 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];
}
这是 EmployeeInfoTableView.h 文件
@interface EmployeeInfoTableView : UITableViewController <UIActionSheetDelegate , MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>{
NSDictionary *empInfo;
NSString *currentPhoneNumber;
NSString *currentEmail;
UIActionSheet *callConfirm;
}
然后我使用 empInfo 在表视图中设置某些字段。
这是我的 dealloc 方法,
- (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:0x00000030
When i run the app and select a row it passes some information to EmployeeInfoPage and works fine. When i hit back and then select the same row. It crashes at the line tableController.empInfo = employee;. I get a EXC_BAD_ACCESS error
- (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];
}
This is the EmployeeInfoTableView.h file
@interface EmployeeInfoTableView : UITableViewController <UIActionSheetDelegate , MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>{
NSDictionary *empInfo;
NSString *currentPhoneNumber;
NSString *currentEmail;
UIActionSheet *callConfirm;
}
Then i use empInfo to set certain fields in the tableview.
This is my dealloc method
- (void)dealloc{
[super dealloc];
[empInfo dealloc];
[currentEmail dealloc];
[currentPhoneNumber dealloc];
[callConfirm dealloc];
}
Is my error becuase i need to release any of my objects?
This is the error i got from off my iPhone, i really have no idea how to read this.
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: 0x00000030
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有看到你的 didSelectRowAtIndexPath 有什么问题,但你的 dealloc 方法肯定不正确。 永远不要在代码中调用dealloc(即仅在使用完对象后才释放它们)。
你的 dealloc 方法应该如下所示:
I don't see anything wrong with your didSelectRowAtIndexPath but your dealloc method is certainly not right. Never call dealloc in your code (i.e. only release the object when you're done with them).
Your dealloc method should look like this:
删除此行
尝试从
didSelectRowAtIndexPath
方法中 。当我们尝试访问之前释放的变量时,会引发EXC_BAD_ACCESS
错误。您正在使用tableController
同时释放NSDictionary *employee
对象。编辑:为了防止您的字典被释放,您可以
复制
字典所需的内容为tableController.empInfo = [employee copy];
,然后释放tableController
最适合这种情况。Try by removing this line
from your
didSelectRowAtIndexPath
method. TheEXC_BAD_ACCESS
error is thrown when we try to access a variable that was released previously. You're simultaneously releasingNSDictionary *employee
object withtableController
.EDIT: To prevent your dictionary from being released, you can
copy
the required contents of the dictionary astableController.empInfo = [employee copy];
and then releasetableController
which would suit this situation best.