1

I recently started to learn objective c and I'm making an application based on tableView, imageview and scrollView.

In tableview you press a button and the application pushes to scrollview where there's an image inside imageview. I get a problem when I tried releasing a memory from imageview (the image I loaded when pressing the button). The problem is, that the image I previously loaded is still there.

Here's the code I've got:

- (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;

}

and i tried to free the memory basically with everyting

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

I don't know what to look for and where the problem lies. Help would be much appreciated :).

P.S. Please note that I've been learning objective c for 4 days now so I'm a newbie

4

0 回答 0