首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“数据格式暂时不可用.”错误

“数据格式暂时不可用.”错误
EN

Stack Overflow用户
提问于 2011-11-22 08:49:48
回答 3查看 474关注 0票数 2

可能重复:

Program received signal: “0”. Data Formatters temporarily unavailable

我把200 OBShapedButtons以上的XiB和设置在那里的背景图像。在此之后,我将获取特定OBShapedButton的图像,并对图像进行着色,并将其重新设置为该OBShapedButton的背景。

代码语言:javascript
复制
-(void)onTick:(NSTimer *)timer {
    //Database
    UIImage *setColor=[[UIImage alloc] init];
    for (int i=0; i<[dataArray count]; i++)
    { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        currentLevelMaleValue =[[[dataArray objectAtIndex:i] objectForKey:@"CurrentLevelMaleColor"] doubleValue];
        printf("Current val is %f",currentLevelMaleValue);
        for (OBShapedButton *obshapedCountryButtons in scrollBaseView.subviews) 
        {
            if (obshapedCountryButtons.tag==i+1) 
            {
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapButton:)];
                tap.numberOfTouchesRequired=1;
                tap.numberOfTapsRequired=1;
                [obshapedCountryButtons addGestureRecognizer:tap];
                [obshapedCountryButtons addTarget:self action:@selector(buttonTagTrap:) forControlEvents:UIControlEventTouchDown];
                //[obshapedCountryButtons addTarget:self action:@selector(tapButton:) forControlEvents:UIControlStateHighlighted];
                setColor=[obshapedCountryButtons imageForState:UIControlStateNormal];
                countryCode =[self getCountryColorCurrentLevel:currentLevelMaleValue];
                setColor =[setColor imageTintedWithColor:countryCode];
                [obshapedCountryButtons setImage:setColor forState:UIControlStateNormal];[pool release];
                //    [setColor release];
                //    [obshapedCountryButtons release];
                //    [tap release]; 
                //         
            }

            //  }
        }
    }
}

现在,我得到了这个errorAfter循环已经执行了大约40次-

程序接收信号:“0”。数据格式暂时不可用,将在“继续”后重试。(加载共享库"/Developer/usr/lib/libXcodeDebuggerSupport.dylib时未知错误)

收到这个警告-

收到内存警告

然后这个应用程序就会被终止。

注:

没有对象分配。

请帮我提一下你的一些想法。我该怎么做?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-11-22 08:57:58

代码语言:javascript
复制
UIImage *setColor=[[UIImage alloc] init];

是内存泄漏,因为您没有释放它。实际上,分配是不必要的,因为您要给它分配一些其他值。类似地,tap也没有发布,因为您已经注释了该代码。

对此有个建议。尝试将这段代码放入NSAutoreleasePool中。

编辑:

代码语言:javascript
复制
-(void)onTick:(NSTimer *)timer {
    //Database
    UIImage *setColor;// =[[UIImage alloc] init];
    for (int i=0; i<[dataArray count]; i++)
    { 
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        currentLevelMaleValue =[[[dataArray objectAtIndex:i] objectForKey:@"CurrentLevelMaleColor"] doubleValue];
        printf("Current val is %f",currentLevelMaleValue);
        for (OBShapedButton *obshapedCountryButtons in scrollBaseView.subviews) 
        {
            NSAutoreleasePool * pool1 = [[NSAutoreleasePool alloc] init];
            if (obshapedCountryButtons.tag==i+1) 
            {
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapButton:)];
                tap.numberOfTouchesRequired=1;
                tap.numberOfTapsRequired=1;
                [obshapedCountryButtons addGestureRecognizer:tap];
                [obshapedCountryButtons addTarget:self action:@selector(buttonTagTrap:) forControlEvents:UIControlEventTouchDown];
                //[obshapedCountryButtons addTarget:self action:@selector(tapButton:) forControlEvents:UIControlStateHighlighted];
                setColor=[obshapedCountryButtons imageForState:UIControlStateNormal];
                countryCode =[self getCountryColorCurrentLevel:currentLevelMaleValue];
                setColor =[setColor imageTintedWithColor:countryCode];
                [obshapedCountryButtons setImage:setColor forState:UIControlStateNormal];[pool release];
                //    [setColor release];
                //    [obshapedCountryButtons release];
                [tap release]; 

            }
            [pool1 drain];
        }
        [pool drain];
    }
}
票数 3
EN

Stack Overflow用户

发布于 2011-11-22 10:21:39

用仪器分析你的应用程序,检查内存泄漏情况。

如果没有泄漏,那么您正在尝试分配过多的内存,因为200个按钮可能会很大。因此,唯一的解决方案是懒洋洋地加载:在任何时候,您应该只在内存中拥有用户可以看到的按钮。

票数 1
EN

Stack Overflow用户

发布于 2011-12-02 15:28:17

内存警告是苹果在iOS中实现的一种内存管理方法。如果设备内存不足,它将发出内存警告。它希望每一个正在运行的应用程序都能通过尽可能多地清除脏内存来响应这个警告。它将执行三轮内存警告。前两个级别是清除内存的基本消息。如果你没有及时回复,或者在第三级之前没有清除足够的内存,你的应用程序就会被终止,因为它和iOS玩的不好。

粘贴在return;if (obshapedCountryButtons.tag==i+1)块的末尾。取消注释[setColor release]; [tap release];代码。使用当前标记查找对象是个坏主意。用一些查找块替换foreach循环。

代码语言:javascript
复制
index = [scrollBaseView.subviews indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {

    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8224103

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档