从内存中释放图像

时间:2013-03-08 19:20:28

标签: objective-c cocoa-touch

我最近开始学习目标c,我正在基于tableView,imageview和scrollView创建一个应用程序。

在tableview中,您按一个按钮,应用程序将推送到scrollview,其中imageview内有图像。当我尝试从imageview(按下按钮时加载的图像)释放内存时出现问题。问题是,我之前加载的图像仍然存在。

这是我得到的代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *headTitle = [[listContent objectAtIndex:indexPath.row] objectForKey:kItemTitleKey];

if ([headTitle isEqualToString:@"Differentialekvationer"]){

    leafViewController.title = headTitle;

    [[self navigationController] pushViewController:leafViewController animated:YES];


    NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/c.png"];
    UIImage *imageToLoad = [UIImage imageWithContentsOfFile:fullpath];
    leafViewController.myImageView = [[UIImageView alloc] initWithImage:imageToLoad];
    leafViewController.myScrollView = [[UIScrollView alloc] initWithFrame:leafViewController.view.bounds];
    [leafViewController.myScrollView addSubview:leafViewController.myImageView];
    leafViewController.myScrollView.contentSize = leafViewController.myImageView.bounds.size;
    [leafViewController.view addSubview:leafViewController.myScrollView];
    leafViewController.myScrollView.bounces = NO;

}else if ([headTitle isEqualToString:@"Gränsvärden"]){

    leafViewController.title = headTitle;

    [[self navigationController] pushViewController:leafViewController animated:YES];

    NSString *fullpath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/e.png"];
    UIImage *imageToLoad = [UIImage imageWithContentsOfFile:fullpath];
    leafViewController.myImageView = [[UIImageView alloc] initWithImage:imageToLoad];
    leafViewController.myScrollView = [[UIScrollView alloc] initWithFrame:leafViewController.view.bounds];
    [leafViewController.myScrollView addSubview:leafViewController.myImageView];
    leafViewController.myScrollView.contentSize = leafViewController.myImageView.bounds.size;
    [leafViewController.view addSubview:leafViewController.myScrollView];
    leafViewController.myScrollView.bounces = NO;

}

我试图基本上用每一个

释放内存
-(void)viewDidDisappear{
leafViewController.myImageView.image = nil;
leafViewController.myScrollView = nil;
leafViewController.view = nil;
[leafViewController.myImageView release];}

我不知道该找什么,问题出在哪里。非常感谢帮助:)。

P.S。请注意,我已经学习了4天的目标c,所以我是新手

0 个答案:

没有答案