2011-09-24 48 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個,而不是全部加載。儘管沒有更多的信息,但我沒有更多的信息可以說。