UIPage Control中的内存泄漏问题

时间:2012-06-05 06:06:03

标签: iphone image ipad pagecontrol

- (void)loadScrollViewWithPage:(int)page
{
    if (page < 0)
    return;
    if (page > kNumberOfPages)
    return;

if([searchResultArray count]>6)
{
    if([searchResultArray count]%6==0)
    {
        kNumberOfPages = [searchResultArray count]/6;
    }
    else {
        kNumberOfPages = [searchResultArray count]/6;
        kNumberOfPages = kNumberOfPages +1;
    }

    pageControl.numberOfPages = kNumberOfPages;
    ScrollView.contentSize = CGSizeMake(ScrollView.frame.size.width *kNumberOfPages, ScrollView.frame.size.height);
}
else {
    kNumberOfPages = 1;
    pageControl.numberOfPages = kNumberOfPages;
}

int z=-1;
int a = 0;

for(UIView *subview in [ScrollView subviews]) 
{
    [subview removeFromSuperview];
}

for(int x = 0; x < [searchResultArray count];x++)
{   
    if(x>=6 && x%6==0)
    {
        z=0;
        a = a+320;
    }
    else {
        z++;
        //a++;
    }

    UIButton *ProfileImageButton = [[UIButton alloc] initWithFrame:CGRectMake(a+8+(100*(x%3))+(x%3)*3,15+(110*(z/3))+(z/3)*10, 100, 85)];
    [ProfileImageButton setBackgroundColor:[UIColor clearColor]];
    [ProfileImageButton setClearsContextBeforeDrawing:YES];
    [ProfileImageButton setTag:x];
    [ProfileImageButton setUserInteractionEnabled:YES];
    NSString *ImagePath =[NSString stringWithFormat:@"%@",[[searchResultArray objectAtIndex:x]valueForKey:@"Photo"]];
    [ProfileImageButton setImageWithURL:[NSURL URLWithString:ImagePath]
                           placeholderImage:[UIImage imageNamed:@"Transparent@2x.png"]];
    [ProfileImageButton addTarget:self action:@selector(profileImageClicked:) forControlEvents:UIControlEventTouchUpInside];
    [ScrollView addSubview:ProfileImageButton];
    [ProfileImageButton release];
    ProfileImageButton = nil; 

    UILabel *groupNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(a+8+(100*(x%3))+(x%3)*3,100+(110*(z/3))+(z/3)*10, 100, 25)];
    [groupNameLabel setBackgroundColor:[UIColor clearColor]];
    [groupNameLabel setText:[NSString stringWithFormat:@"%@,%@,%@",[[searchResultArray objectAtIndex:x] valueForKey:@"Username"],[[searchResultArray objectAtIndex:x] valueForKey:@"Age"],[[searchResultArray objectAtIndex:x] valueForKey:@"Gender"]]];
    [groupNameLabel setUserInteractionEnabled:YES];
    [groupNameLabel setFont:[UIFont systemFontOfSize:15.0f]];
    [groupNameLabel setTextColor:[UIColor whiteColor]];
    [ScrollView addSubview:groupNameLabel];
    [groupNameLabel release];
    groupNameLabel = nil;
}   

}

- (void)scrollViewDidScroll:(UIScrollView *)sender
{
 if (pageControlUsed)
    {
    return;
}

CGFloat pageWidth = ScrollView.frame.size.width;
int page = floor((ScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
pageControl.currentPage = page;


[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
pageControlUsed = NO;
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
pageControlUsed = NO;
}

- (void)changePage:(id)sender
{
int page = pageControl.currentPage;

[self loadScrollViewWithPage:page - 1];
[self loadScrollViewWithPage:page];
[self loadScrollViewWithPage:page + 1];

// update the scroll view to the appropriate page
CGRect frame = ScrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[ScrollView scrollRectToVisible:frame animated:YES];

pageControlUsed = YES;
}

我正在开发一个应用程序,我正在从服务器检索图像,这些图像将显示在UIPageControl上,虽然我已经这样做了。但是滚动页面控制多次显示内存泄漏警告和应用程序退出

ON CONSOLE

  

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

0 个答案:

没有答案