草庐IT

ios - 呈现模态 UIViewController 时发生奇怪的崩溃

coder 2023-09-23 原文

我看过几次这个崩溃报告。极其随意和稀有,看不懂。我所做的只是使用以下代码呈现模态视图 Controller

ComposeController *newcontrol = [[ComposeController alloc]initWithMode:1 withNIB:@"ComposeController"];
newcontrol.delegate = self;

UINavigationController  *holder = [[UINavigationController alloc] initWithRootViewController:newcontrol];
[self presentViewController:holder animated:YES completion:NULL];

不知何故,这完全是随机的:

OS Version:      iPhone OS 6.1 (10B143)
Report Version:  104

Exception Type:  SIGSEGV
Exception Codes: SEGV_ACCERR at 0x9
Crashed Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                     0x3b25c5d0 objc_msgSend + 16
1   CoreFoundation                      0x334ba73f -[__NSPlaceholderArray initWithObjects:count:] + 271
2   CoreFoundation                      0x334bae09 +[NSArray arrayWithObject:] + 45
3   UIKit                               0x353e80ab -[UIWindow _rotationViewControllers] + 51
4   UIKit                               0x353e7fe3 -[UIViewController viewControllerForRotation] + 91
5   UIKit                               0x353e7f39 -[UIViewController _visibleView] + 97
6   UIKit                               0x3546c05b -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 2483
7   UIKit                               0x3546afab -[UIViewController presentViewController:withTransition:completion:] + 3399
8   MyApp                               0x00046e97 -[Inbox composeHit] (Inbox.m:207)

最佳答案

我一直有同样的问题。这似乎是由于我从弹出窗口中呈现模态视图 Controller 这一事实引起的,它没有经过很好的测试并触发了 Apple 代码中的错误。错误是 UIKit 保留了对我的 View Controller 的未保留引用,该引用已经被解除和释放,因此稍后会命中该引用。我的解决方法是要么避免从弹出窗口中呈现模态 VC,要么自己无限期地保留所有此类 VC(在成员变量或类似变量中)。

下面是血淋淋的细节。

这是我用来触发问题的代码。

-(void) handlePinchFromCell:(AMPSupportingPhotoCell*) cell
{
    UIViewController * vc = [[UIViewController alloc] init]; // UIViewController #0
    [self presentViewController:vc animated:YES completion:nil];
    [self performSelector:@selector(dismiss:) withObject:vc afterDelay:2];
}

-(void) dismiss:(UIViewController*)vc
{
    [self dismissViewControllerAnimated:YES completion:^(){NSLog(@"-------");}];
}

此代码是 UIViewController #1 的一部分,它位于 UIPopoverController 内,它从另一个 UIViewController #2 弹出,它本身是从另一个 View UIViewController #3 呈现的。崩溃发生在弹出窗口关闭后, Controller #2 id 被关闭。

如果我启用 Zombies,我会得到相同的堆栈跟踪,但有一条消息:

2013-03-13 20:04:24.681 Mercury[16698:19d03] handlePinchFromCell: a225710
2013-03-13 20:04:27.083 Mercury[16698:19d03] -------
2013-03-13 20:04:31.606 Mercury[16698:19d03] *** -[UIViewController retain]: message sent to deallocated instance 0xa225710

因此,请注意 VC#0 已分配、显示、2 秒后解除、释放,但在 Apple 代码的某处仍然存在对它的悬空引用。当弹出窗口关闭并且 VC#2 被关闭时,整个事情都会崩溃,试图访问已释放的 VC。我相当确定这是Apple的错误。我还猜想它与从弹出窗口中呈现 VC 有关,所以如果你远离它,或者自己保留 VC,你应该没问题。

同一问题的另一个堆栈跟踪是这样的。如果上面的代码运行两次,就会发生这种情况:

2013-03-13 20:12:53.883 Mercury[16735:19d03] handlePinchFromCell: 16d54da0
2013-03-13 20:12:56.285 Mercury[16735:19d03] -------
2013-03-13 20:13:03.481 Mercury[16735:19d03] handlePinchFromCell: a2565f0
2013-03-13 20:13:03.481 Mercury[16735:19d03] *** -[UIViewController isKindOfClass:]: message sent to deallocated instance 0x16d54da0
(lldb) bt
* thread #1: tid = 0x1f03, 0x017f8a97 CoreFoundation`___forwarding___ + 295, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
    frame #0: 0x017f8a97 CoreFoundation`___forwarding___ + 295
    frame #1: 0x017f894e CoreFoundation`_CF_forwarding_prep_0 + 14
    frame #2: 0x00c42f90 UIKit`-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 907
    frame #3: 0x00a40ee3 UIKit`-[UIViewController presentViewController:withTransition:completion:] + 4521
    frame #4: 0x00a41167 UIKit`-[UIViewController presentViewController:animated:completion:] + 112
    frame #5: 0x0006c32d Mercury`-[AMPSupportingPhotosViewController handlePinchFromCell:](self=0x16d55360, _cmd=0x0007a64a, cell=0x0a22a2a0) + 205 at AMPSupportingPhotosViewController.m:184
    frame #6: 0x015336b0 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
    frame #7: 0x0006f317 Mercury`-[AMPSupportingPhotoCell handlePinch:](self=0x0a22a2a0, _cmd=0x00efb0db, sender=0x0a2504a0) + 215 at AMPSupportingPhotoCell.m:53
    frame #8: 0x00c2185a UIKit`_UIGestureRecognizerSendActions + 139

关于ios - 呈现模态 UIViewController 时发生奇怪的崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14967840/

有关ios - 呈现模态 UIViewController 时发生奇怪的崩溃的更多相关文章

  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 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)(人们推荐的最少

  3. 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返回它复制的字节数,但是当我还没有下

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

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

  5. ruby-on-rails - 启用 Rack::Deflater 时 ETag 发生变化 - 2

    在启用Rack::Deflater来gzip我的响应主体时偶然发现了一些奇怪的东西。也许我遗漏了一些东西,但启用此功能后,响应被压缩,但是资源的ETag在每个请求上都会发生变化。这会强制应用程序每次都响应,而不是发送304。这在没有启用Rack::Deflater的情况下有效,我已经验证页面源没有改变。我正在运行一个使用thin作为Web服务器的Rails应用程序。Gemfile.lockhttps://gist.github.com/2510816有没有什么方法可以让我从Rack中间件获得更多的输出,这样我就可以看到发生了什么?提前致谢。 最佳答案

  6. 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使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  7. ruby - Hanami link_to 助手只呈现最后一个元素 - 2

    我是HanamiWorld的新人。我已经写了这段代码:moduleWeb::Views::HomeclassIndexincludeWeb::ViewincludeHanami::Helpers::HtmlHelperdeftitlehtml.headerdoh1'Testsearchengine',id:'title'hrdiv(id:'test')dolink_to('Home',"/",class:'mnu_orizontal')link_to('About',"/",class:'mnu_orizontal')endendendendend我在模板上调用了title方法。htm

  8. ruby - 当 attr_accessor 在类方法中时会发生什么? - 2

    所以我想到了这个,想知道当下面的一些事情完成后会发生什么。classTestdefself.abcattr_accessor:Johnendendobject=Test.newputs"beforecallingclassmethodabc:#{object.class.instance_methods(false)}"Test.abcputs"aftercallingclassmethodabc:#{object.class.instance_methods(false)}"这里我检查的是,getter和setter方法是否以这种方式创建。如果是这样,是那些实例方法或类方法。首先我创

  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-on-rails - 浮点乘法的 Ruby 奇怪问题 - 2

    有没有人用ruby​​解决这个问题:假设我们有:a=8.1999999我们想将它四舍五入为2位小数,即8.20,然后乘以1,000,000得到8,200,000我们是这样做的;(a.round(2)*1000000).to_i但是我们得到的是8199999,为什么?奇怪的是,如果我们乘以1000、100000或10000000而不是1000000,我们会得到正确的结果。有人知道为什么吗?我们正在使用ruby​​1.9.2并尝试使用1.9.3。谢谢! 最佳答案 每当你在计算中得到时髦的数字时使用bigdecimalrequire'bi

随机推荐