2011-09-24 50 views
0

我正在开发使用许多照片所以肯定它崩溃了,虽然我发布了图片的一些部分在下面的代码所示我需要在iPhone内存管理帮助

-(void)addScrollView{ 
[self selectData]; 


scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(5, 0, 300, 160)]; 
int counter=10; 
float y=10.0f; 
int fullLength=[photoArray count]; 
int horizontal=(fullLength/2)*80; 
int vertical=160; 
int c1=1; 
for(int c=0;c<[photoArray count];c++){ 
    PhotoData *d=[photoArray objectAtIndex:c]; 
    //NSLog(d.photoPath); 
    if(c==fullLength/2 &&c1<3){ 
     counter=10; 
     y=y+80.0f; 
     c1++; 

    } 
    UIImage *img1=[[UIImage alloc]initWithContentsOfFile:d.photoPath]; 
    UIButton* button = [[UIButton alloc] init]; 
    [button setTitle:@"Delete" forState:UIControlStateNormal]; 
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]; 
    button.tag=d.photoId; 

    //set the button states you want the image to show up for 
    [button setBackgroundImage:img1 forState:UIControlStateNormal]; 
    [button setFrame:CGRectMake(counter, y, 70.0, 70.0)]; 

    //create the touch event target, i am calling the 'productImagePressed' method 
    [button addTarget:self action:@selector(deleteImage:) 
    forControlEvents:UIControlEventTouchUpInside]; 
     [scrollView addSubview:button]; 
    counter=counter+80.0f; 
    [img1 release]; 
    [button release]; 

} 
[scrollView setContentSize:CGSizeMake(horizontal, vertical)]; 


[self.view addSubview:scrollView]; 
[scrollView release]; 

} 

的dealloc也没有叫,因为我的应用我正在使用基于Tab的应用程序。 那么请大家帮忙解决这个内存管理问题。

+0

它在哪里崩溃?什么样的崩溃? –

+0

数据格式化程序错误 – Mario

+2

错误...似乎与您的代码或内存管理问题无关。你能澄清/扩大吗? – FeifanZ

回答

2

唯一的问题是你提到的 - 你可能有太多的图像或对象加载。在这种情况下,您可能希望将一些数据保存到幕后文件中,并根据需要进行提取。可能不是将所有对象存储在photoArray中,而是写入一个文件(甚至可以将文件路径写入文件),并且一次批量加载10个,而不是全部加载。尽管没有更多的信息,但我没有更多的信息可以说。