草庐IT

ios - 当同一行被选中两次时 UITableView 崩溃

coder 2024-01-21 原文

当我运行该应用程序并选择一行时,它将一些信息传递给 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 在 tableview 中设置某些字段。

这是我的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

最佳答案

我没有发现您的 didSelectRowAtIndexPath 有任何问题,但您的 dealloc 方法肯定不对。 永远不要在您的代码中调用 dealloc(即仅在您使用完对象后才释放对象)。

你的 dealloc 方法应该是这样的:

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

关于ios - 当同一行被选中两次时 UITableView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9155455/

有关ios - 当同一行被选中两次时 UITableView 崩溃的更多相关文章

  1. ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃 - 2

    为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

  2. ruby - Highline 询问方法不会使用同一行 - 2

    设置:狂欢ruby1.9.2高线(1.6.13)描述:我已经相当习惯在其他一些项目中使用highline,但已经有几个月没有使用它了。现在,在Ruby1.9.2上全新安装时,它似乎不允许在同一行回答提示。所以以前我会看到类似的东西:require"highline/import"ask"Whatisyourfavoritecolor?"并得到:Whatisyourfavoritecolor?|现在我看到类似的东西:Whatisyourfavoritecolor?|竖线(|)符号是我的终端光标。知道为什么会发生这种变化吗? 最佳答案

  3. Ruby Readline 在向上箭头上使控制台崩溃 - 2

    当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby​​安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少

  4. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  5. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  6. ruby - Rails 关联 - 同一个类的多个 has_one 关系 - 2

    我的问题的一个例子是体育游戏。一场体育比赛有两支球队,一支主队和一支客队。我的事件记录模型如下:classTeam"Team"has_one:away_team,:class_name=>"Team"end我希望能够通过游戏访问一个团队,例如:Game.find(1).home_team但我收到一个单元化常量错误:Game::team。谁能告诉我我做错了什么?谢谢, 最佳答案 如果Gamehas_one:team那么Rails假设您的teams表有一个game_id列。不过,您想要的是games表有一个team_id列,在这种情况下

  7. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  8. ruby-on-rails - Rake 任务仅调用一次时执行两次 - 2

    我写了一个非常简单的rake任务来尝试找到这个问题的根源。namespace:foodotaskbar::environmentdoputs'RUNNING'endend当在控制台中执行rakefoo:bar时,输出为:RUNNINGRUNNING当我执行任何rake任务时会发生这种情况。有没有人遇到过这样的事情?编辑上面的rake任务就是写在那个.rake文件中的所有内容。这是当前正在使用的Rakefile。requireFile.expand_path('../config/application',__FILE__)OurApp::Application.load_tasks这里

  9. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  10. ruby - 在 Ruby 中,为什么 Array.new(size, object) 创建一个由对同一对象的多个引用组成的数组? - 2

    如thisanswer中所述,Array.new(size,object)创建一个数组,其中size引用相同的object。hash=Hash.newa=Array.new(2,hash)a[0]['cat']='feline'a#=>[{"cat"=>"feline"},{"cat"=>"feline"}]a[1]['cat']='Felix'a#=>[{"cat"=>"Felix"},{"cat"=>"Felix"}]为什么Ruby会这样做,而不是对object进行dup或clone? 最佳答案 因为那是thedocumenta

随机推荐