我们如何关闭NSFileManager?

时间:2013-04-29 13:27:30

标签: ios objective-c xcode uiimageview nsfilemanager

在我的ios应用程序中,我使用了大量图像(大约一千个)来显示有关产品的信息。然后我在运行时遇到了这样的错误;

  

ImageIO:CGImageRead_mapData'open'失败   错误= 24(打开的文件太多)

如何关闭打开的文件?我正在使用NSFileManager。

感谢您的回答。

更新:

我的viewdidload中的一些代码,

while(sqlite3_step(compiledStatement) == SQLITE_ROW)  {
                    NSString *imageName= [NSString stringWithUTF8String:(char*)sqlite3_column_text(compiledStatement, 2)];
                    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                    NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
                    NSString *filePath = [documentsPath stringByAppendingPathComponent:imageName];

                    NSData *pngData = [NSData dataWithContentsOfFile:filePath];
                    if (pngData == nil) {
                        image2 = [UIImage imageNamed:@"resimYok.jpeg"];//horoda
                    }else{
                        image2 = [UIImage imageWithData:pngData];
                    }
                    image2=[image2 imageByScalingAndCroppingForSize:CGSizeMake(175, 210)];

                    UIButton * urunDetayButton = [UIButton buttonWithType:UIButtonTypeCustom];
                    [urunDetayButton setFrame:CGRectMake(column*197+38 , row*350+58, 159, 170)];
                    [urunDetayButton setImage:image2 forState:UIControlStateNormal];
                    [urunDetayButton addTarget:self
                                        action:@selector(buttonClicked:)
                              forControlEvents:UIControlEventTouchUpInside];
                    urunDetayButton.tag = UrunId;
                    [scrollView addSubview:urunDetayButton];

                    UIImageView *background = [[UIImageView alloc]initWithFrame:CGRectMake(column*197+30, row*350, 175, 280)];
                    UIImage *blackBackGround = [UIImage imageNamed:@"BackImage.png"];
                    [background setImage:blackBackGround];                                            
                    [scrollView addSubview:background];
                    [background release];
                    [blackBackGround release];

                    UIImage *sepeteEkleButtonImage = [UIImage imageNamed:@"sepeteEkleButtonImage.png"];
                    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
                    [button setFrame:CGRectMake(column*197+38 , row*350+8, 159, 45)];
                    [button setImage:sepeteEkleButtonImage forState:UIControlStateNormal];
                    [button addTarget:self
                               action:@selector(addToChart:)
                     forControlEvents:UIControlEventTouchUpInside];
                    button.tag = UrunId;

                    [sepeteEkleButtonImage release];
                }

在这个循环中,我创建了数千个按钮。但我看不到一些按钮和一些imageview的图像。例如,“背景”和“按钮”图像视图和按钮。有两个屏幕截图,必须是和。

this one must be i want this one is current state

1 个答案:

答案 0 :(得分:0)

使用下一种语法创建图像可能会更好:

[UIImage imageWithContentsOfFile:filePath];