Imagecache. h
//
// Imagecache. h
// Nowlearn
//
// Created by Wang doublejie on 12-9-12.
// Copyright (c) 2012 _ mycompanyname _. All rights reserved.
//
// Image cache class
# Import <Foundation/Foundation. h>
@ Interface imagecache: nsobject
{
}
+ (Uiimage *) LoadImage :( nsstring *) imagename;
+ (Void) releasecache;
@ End
Imagecache. m
//
// Imagecache. m
// Nowlearn
//
// Created by Wang doublejie on 12-9-12.
// Copyright (c) 2012 _ mycompanyname _. All rights reserved.
//
# Import "imagecache. H"
@ Implementation imagecache
Static nsmutabledictionary * dict;
+ (Uiimage *) LoadImage :( nsstring *) imagename
{
If (! Dict) dict = [nsmutabledictionary
Dictionary] retain];
Uiimage * image = [dict
Objectforkey: imagename];
If (! Image ){
Nsstring * ImagePath = [[nsbundle
Mainbundle] pathforresource: imagename
Oftype: Nil];
Image = [uiimage imagewithcontentsoffile: ImagePath];
If (image ){
[Dict setobject: Image
Forkey: imagename];
}
}
Return image;
}
+ (Void) releasecache
{
If (dict ){
[Dict removeallobjects];
}
}
@ End
// Use
-(Void) viewdidload
{
[Super
Viewdidload];
Nsmutablearray * images = [nsmutablearray
Alloc] initwithcapacity: 30];
For (INT I = 1; I <= 9; I ++ ){
Nsstring * imagename = [nsstring
Stringwithformat: @ "page_0000d.jpg", I];
Uiimage * image = [imagecache
LoadImage: imagename];
[Images addobject: Image];
}
Imageview = [[uiimageview
Alloc] initwithframe: cgrectmake (0,100,320,320)];
Imageview. animationimages = images;
[Images release];
Imageview. animationduration = 10;
Imageview. animationrepeatcount = 100;
[Imageview startanimating];
[Self. View
Addsubview: imageview];
Uibutton * BTN = [uibutton
Buttonwithtype: uibuttontyperoundedrect];
BTN. Frame = cgrectmake (30,420, 90, 35 );
[BTN settitle: @ "clear memory usage" forstate: uicontrolstatenormal];
[BTN settitle: @ "clear memory usage" forstate: uicontrolstatehighlighted];
[BTN addtarget: Self
Action: @ selector (clearmemory :)
Forcontrolevents: uicontroleventtouchupinside];
[Self. View
Addsubview: BTN];
// Do any additional setup after loading the view.
}