Ios 为什么我的[UIScrollView removeFromSuperview]会崩溃?

Ios 为什么我的[UIScrollView removeFromSuperview]会崩溃?,ios,ipad,animation,uiscrollview,Ios,Ipad,Animation,Uiscrollview,下面是崩溃日志 您知道[UIScrollView removeFromSuperview]会崩溃的具体原因吗?scrollview包含具有不同类型的UIView的视图层次结构。我还发现,临时版本崩溃通常不是调试版本。我找不到任何理由 在iPhone中,相同的viewcontroller加载到不同的流中,效果良好。但在iPad上它崩溃了。 在iPad中,在容器视图控制器中,仅加载viewcontroler.view Incident Identifier: EE102239-34D1-4BE7-8

下面是崩溃日志

您知道
[UIScrollView removeFromSuperview]
会崩溃的具体原因吗?scrollview包含具有不同类型的
UIView
的视图层次结构。我还发现,临时版本崩溃通常不是调试版本。我找不到任何理由

在iPhone中,相同的viewcontroller加载到不同的流中,效果良好。但在iPad上它崩溃了。 在iPad中,在容器视图控制器中,仅加载viewcontroler.view

Incident Identifier: EE102239-34D1-4BE7-8B52-41F74AB26203
CrashReporter Key:   2b11ea2a01ac5618e199ffc5a1e1f321600bb6a9
Hardware Model:      iPad3,4
Version:         ??? (???)
Code Type:       ARM (Native)
Parent Process:  launchd [1]

Date/Time:       2013-06-18 15:19:16.132 +0200
OS Version:      iOS 6.1.3 (10B329)
Report Version:  104

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

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x3bab7070 prepareForMethodLookup + 20
1   libobjc.A.dylib                 0x3bab6fb2 lookUpMethod + 42
2   libobjc.A.dylib                 0x3bab6f7e _class_lookupMethodAndLoadCache3 + 14
3   libobjc.A.dylib                 0x3bab6638 objc_msgSend_uncached + 24
4   QuartzCore                      0x357f2a72 CA::Layer::contents_visibility_changed(CA::Transaction*, bool) + 50
5   QuartzCore                      0x357f29de CA::Layer::mark_visible(CA::Transaction*, bool) + 190
6   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
7   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
8   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
9   QuartzCore                      0x357f29b2 CA::Layer::mark_visible(CA::Transaction*, bool) + 146
10  QuartzCore                      0x357f28d2 CA::Layer::update_removed_sublayer(CA::Transaction*, unsigned int) + 18
11  QuartzCore                      0x357f255a CA::Layer::remove_sublayer(CA::Transaction*, CALayer*) + 130
12  QuartzCore                      0x357f246a CA::Layer::remove_from_superlayer() + 34
13  UIKit                           0x35a6e92c -[UIView(Hierarchy) removeFromSuperview] + 144
14  UIKit                           0x35b857bc -[UIScrollView removeFromSuperview] + 60
15  MyApp           0x000bde8a -[iPadNavigationController vcAnimationDone] (iPadNavigationController.m:400)
16  UIKit                           0x35a55ab6 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 154
17  UIKit                           0x35aca8f8 -[UIViewAnimationState animationDidStop:finished:] + 44
18  QuartzCore                      0x35801304 CA::Layer::run_animation_callbacks(void*) + 204
19  libdispatch.dylib               0x3bed55d8 _dispatch_client_callout + 20
20  libdispatch.dylib               0x3bed8e40 _dispatch_main_queue_callback_4CF + 224
21  CoreFoundation                  0x33c051ac __CFRunLoopRun + 1284
22  CoreFoundation                  0x33b78238 CFRunLoopRunSpecific + 352
23  CoreFoundation                  0x33b780c4 CFRunLoopRunInMode + 100
24  GraphicsServices                0x37733336 GSEventRunModal + 70
25  UIKit                           0x35a942b4 UIApplicationMain + 1116
代码中的几行(按要求)


一个很可能的原因是,您正在过度扩展您的scrollview或其中一个视图


调用
removeFromSuperview
然后解除视图分配,而不是简单地减少保留计数。

实际上,如果您仍然使用非ARC项目,对于此类错误非常有用。保留/释放平衡问题很难确定,而且不完整的方法几乎不可能解决,因此我建议您尽可能发布完整的方法正文。

感谢大家的回答、提示和技巧。不过有一件事我想和大家分享,那就是这次坠机的原因。我发现,在不同的时间,崩溃发生在不同的线程。在我的iPad应用程序中,有几个视图加载了按键/菜单。一些按钮按下从web服务获取数据。因此,我有点困惑,以获得崩溃,动画,或url连接等原因。。。我尝试使用已启用的NSZombie对象,但它没有显示任何信息。 然后我试着和警卫马洛克在一起。这只在模拟器中运行。我神奇地找到了崩溃的密码点。我有一个将十六进制字符串转换成数据的函数。在这里,我有一行代码使C字符串以null结尾。其中,我在最后一个索引处指定了0。这就是坠机的原因

tmpCh[count] = 0;
我不知道为什么,但可能在iOS中的内存管理过程中需要一些时间,所以它会在不同的线程、不同的时间崩溃。但在模拟器中使用Guard malloc时,它总是在这里指出,当我重写代码时,崩溃消失了

/* Converts a hex string to bytes.
 Precondition:
 . The hex string can be separated by space or not.
 . the string length without space or 0x, must be even. 2 symbols for one byte/char
 . sample input: 23 3A F1 OR 233AF1
 */
+ (NSData *) dataFromHexString:(NSString*)hexString
{

    if (hexString.length < 1) {
        return nil;
    }

    char * tmpCh = (char *) malloc([hexString length] * sizeof(char));
    int count = 0;
    for (int k=0; k<hexString.length;k++) {
        char c = [hexString characterAtIndex:k];

        if (c == (char)0x20) { //skip space
            continue;
        }

        if (c == '0') { // skip 0x
            if(k+1 < hexString.length){
                if ([hexString characterAtIndex:k+1] == 'x'
                    || [hexString characterAtIndex:k+1] == 'X' )
                {
                    k = k + 1;
                    continue;
                }
            }
        }

        tmpCh[count] = c;
        count++;
    }
    tmpCh[count] = 0; // make null terminated string

    if (count % 2) {
        return nil;
    }

    NSString *temp = [[NSString alloc] initWithUTF8String:tmpCh];
    free(tmpCh);

    if ([temp length] % 2 != 0) {
        return  nil;
    }

    NSMutableData *result = [[NSMutableData alloc] init];
    unsigned char byte;
    char hexChars[3] = {0};
    for (int i=0; i < (temp.length/2); i++) {
        hexChars[0] = [temp characterAtIndex:i*2];
        hexChars[1] = [temp characterAtIndex:i*2+1];

        if (![Util isValidChar:hexChars[0]] || ![Util isValidChar:hexChars[1]]) {
            return nil;
        }
        byte = strtol(hexChars, NULL, 16);
        [result appendBytes:&byte length:1];
    }

    NSData * data = [NSData dataWithData:result];
    [result release];
    return data;
}
/*将十六进制字符串转换为字节。
前提条件:
. 十六进制字符串可以用空格分隔,也可以不用空格分隔。
. 不带空格或0x的字符串长度必须为偶数。2个符号表示一个字节/字符
. 样本输入:23 3A F1或233AF1
*/
+(NSData*)dataFromHexString:(NSString*)hexString
{
if(hextstring.length<1){
返回零;
}
char*tmpCh=(char*)malloc([hextstring length]*sizeof(char));
整数计数=0;

对于(int k=0;kCan您可以发布导致崩溃的代码。是否有可能另一个动画仍在运行?似乎有一些消息要发送到
nil
实例。它是在ARC下编译的吗?尝试在模拟器中运行它,并使用查找僵尸的仪器您为哪个版本的iOS编写?手动引用计数,动画方法在iOS4中被弃用的s…对于iOS 4.3。对于iPad中的每个按钮按下,我都有4个vc要加载。加载时会重新加载动画。因此,加载另一个vc时会运行其他动画。我无法在调试模式下复制它,只有临时模式我有此错误。
/* Converts a hex string to bytes.
 Precondition:
 . The hex string can be separated by space or not.
 . the string length without space or 0x, must be even. 2 symbols for one byte/char
 . sample input: 23 3A F1 OR 233AF1
 */
+ (NSData *) dataFromHexString:(NSString*)hexString
{

    if (hexString.length < 1) {
        return nil;
    }

    char * tmpCh = (char *) malloc([hexString length] * sizeof(char));
    int count = 0;
    for (int k=0; k<hexString.length;k++) {
        char c = [hexString characterAtIndex:k];

        if (c == (char)0x20) { //skip space
            continue;
        }

        if (c == '0') { // skip 0x
            if(k+1 < hexString.length){
                if ([hexString characterAtIndex:k+1] == 'x'
                    || [hexString characterAtIndex:k+1] == 'X' )
                {
                    k = k + 1;
                    continue;
                }
            }
        }

        tmpCh[count] = c;
        count++;
    }
    tmpCh[count] = 0; // make null terminated string

    if (count % 2) {
        return nil;
    }

    NSString *temp = [[NSString alloc] initWithUTF8String:tmpCh];
    free(tmpCh);

    if ([temp length] % 2 != 0) {
        return  nil;
    }

    NSMutableData *result = [[NSMutableData alloc] init];
    unsigned char byte;
    char hexChars[3] = {0};
    for (int i=0; i < (temp.length/2); i++) {
        hexChars[0] = [temp characterAtIndex:i*2];
        hexChars[1] = [temp characterAtIndex:i*2+1];

        if (![Util isValidChar:hexChars[0]] || ![Util isValidChar:hexChars[1]]) {
            return nil;
        }
        byte = strtol(hexChars, NULL, 16);
        [result appendBytes:&byte length:1];
    }

    NSData * data = [NSData dataWithData:result];
    [result release];
    return data;
}